aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2018-03-21 06:46:03 +0300
committerValentin Popov <info@valentineus.link>2018-03-21 06:46:03 +0300
commit4833a44b519d1f85ef890a0d0e1be2beb92bf63b (patch)
tree1ddd0362fadbdff889d412d98c8380040bcd9b42
parentd7185f59256e4ebf7a311d40b563c60193ff59be (diff)
downloadlocal_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.php29
1 files 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;
}