diff options
author | Valentin Popov <info@valentineus.link> | 2018-03-21 06:46:03 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-03-21 06:46:03 +0300 |
commit | 4833a44b519d1f85ef890a0d0e1be2beb92bf63b (patch) | |
tree | 1ddd0362fadbdff889d412d98c8380040bcd9b42 | |
parent | d7185f59256e4ebf7a311d40b563c60193ff59be (diff) | |
download | local_webhooks-4833a44b519d1f85ef890a0d0e1be2beb92bf63b.tar.xz local_webhooks-4833a44b519d1f85ef890a0d0e1be2beb92bf63b.zip |
Redesigned feature a list of services
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r-- | lib.php | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -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; } |