From 4833a44b519d1f85ef890a0d0e1be2beb92bf63b Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 21 Mar 2018 07:46:03 +0400 Subject: Redesigned feature a list of services Signed-off-by: Valentin Popov --- lib.php | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib.php b/lib.php index d2550af..ce2bb8c 100644 --- a/lib.php +++ b/lib.php @@ -122,22 +122,37 @@ function local_webhooks_get_record($serviceid) { } /** - * Get all records from the database. + * Get a list of services from the database. * - * @param number $limitfrom - * @param number $limitnum - * @param array $conditions - * @return array + * @param number $limitfrom Start position + * @param number $limitnum End position + * @param array $conditions List of conditions + * @return array List of services */ function local_webhooks_get_list_records($limitfrom = 0, $limitnum = 0, $conditions = array()) { global $DB; - $records = $DB->get_records(LOCAL_WEBHOOKS_TABLE_SERVICES, $conditions, "id", "*", $limitfrom, $limitnum); + /* Checks for the presence of a cache */ + $cachename = crc32($limitfrom . $limitnum . serialize($conditions)); + if (is_array($records = local_webhooks_cache_get($cachename))) { + return $records; + } - foreach ($records as $record) { + /* Loads a list of services */ + $rs = $DB->get_recordset(LOCAL_WEBHOOKS_TABLE_SERVICES, $conditions, "id", "*", $limitfrom, $limitnum); + $records = array(); + + foreach ($rs as $record) { + /* Loads a list of service events */ $record->events = local_webhooks_get_list_events_for_service($record->id); + $records[] = $record; } + $rs->close(); + + /* Saves the result in the cache */ + local_webhooks_cache_set($cachename, $records); + return $records; } -- cgit v1.2.3