From 4f75d9c5c8b927f2c0d125b47ab86bde74275a89 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 18 Feb 2018 22:05:58 +0400 Subject: Event handler is rewritten to work with the cache --- classes/handler.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'classes') diff --git a/classes/handler.php b/classes/handler.php index 3349f9f..eb0905f 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -26,6 +26,7 @@ namespace local_webhooks; defined("MOODLE_INTERNAL") || die(); +require_once(__DIR__ . "/../locallib.php"); require_once(__DIR__ . "/../lib.php"); /** @@ -43,12 +44,13 @@ class handler { public static function events($event) { $data = $event->get_data(); - if ($callbacks = local_webhooks_get_list_records()) { - foreach ($callbacks as $callback) { - if (boolval($callback->enable) && !empty($callback->events[$data["eventname"]])) { - local_webhooks_send_request($data, $callback); - } - } + if (!is_array($recordlist = local_webhooks_cache_get($data["eventname"]))) { + $recordlist = local_webhooks_search_services_by_event($data["eventname"]); + local_webhooks_cache_set($data["eventname"], $recordlist); + } + + foreach ($recordlist as $record) { + local_webhooks_send_request($data, $record); } } } \ No newline at end of file -- cgit v1.2.3