Added cache to the search function
Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
parent
5036ef261c
commit
279fca5ed1
15
lib.php
15
lib.php
@ -55,9 +55,17 @@ function local_webhooks_change_status($serviceid) {
|
|||||||
function local_webhooks_search_record($eventname, $limitfrom = 0, $limitnum = 0) {
|
function local_webhooks_search_record($eventname, $limitfrom = 0, $limitnum = 0) {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
|
/* Checks for the presence of a cache */
|
||||||
|
$namecache = "${eventname}_${limitfrom}_${limitnum}";
|
||||||
|
if (is_array($records = local_webhooks_cache_get($namecache))) {
|
||||||
|
return $records;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Loads a list of events */
|
||||||
$rs = $DB->get_recordset(LOCAL_WEBHOOKS_TABLE_EVENTS, array("name" => $eventname, "status" => true), "id", "*", $limitfrom, $limitnum);
|
$rs = $DB->get_recordset(LOCAL_WEBHOOKS_TABLE_EVENTS, array("name" => $eventname, "status" => true), "id", "*", $limitfrom, $limitnum);
|
||||||
$result = array();
|
$result = array();
|
||||||
|
|
||||||
|
/* Loads services */
|
||||||
foreach ($rs as $event) {
|
foreach ($rs as $event) {
|
||||||
if ($record = $DB->get_record(LOCAL_WEBHOOKS_TABLE_SERVICES, array("id" => $event->serviceid, "status" => true), "*", IGNORE_MISSING)) {
|
if ($record = $DB->get_record(LOCAL_WEBHOOKS_TABLE_SERVICES, array("id" => $event->serviceid, "status" => true), "*", IGNORE_MISSING)) {
|
||||||
$result[] = $record;
|
$result[] = $record;
|
||||||
@ -66,6 +74,9 @@ function local_webhooks_search_record($eventname, $limitfrom = 0, $limitnum = 0)
|
|||||||
|
|
||||||
$rs->close();
|
$rs->close();
|
||||||
|
|
||||||
|
/* Saves the result in the cache */
|
||||||
|
local_webhooks_cache_set($namecache, $result);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,14 +273,14 @@ function local_webhooks_restore_backup($backup) {
|
|||||||
/**
|
/**
|
||||||
* Send the event remotely to the service.
|
* Send the event remotely to the service.
|
||||||
*
|
*
|
||||||
* @param array $event
|
* @param object $event
|
||||||
* @param object $record
|
* @param object $record
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
function local_webhooks_send_request($event, $record) {
|
function local_webhooks_send_request($event, $record) {
|
||||||
global $CFG;
|
global $CFG;
|
||||||
|
|
||||||
$event["host"] = parse_url($CFG->wwwroot)["host"];
|
$event["host"] = parse_url($CFG->wwwroot)["host"]; /* @todo: Fucking shit */
|
||||||
$event["token"] = $record->token;
|
$event["token"] = $record->token;
|
||||||
$event["extra"] = $record->other;
|
$event["extra"] = $record->other;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user