Skip to content

Commit 858194d

Browse files
author
Vithusha Kethiri
committed
Optimize tagsummary
1 parent 6597da7 commit 858194d

File tree

4 files changed

+58
-2
lines changed

4 files changed

+58
-2
lines changed

classes/local/tag/tag_manager.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,21 @@ public static function get_sync_status_string(int $tagsyncstatus): string {
227227
*/
228228
public static function get_tag_sync_status_summary(): array {
229229
global $DB;
230-
return $DB->get_records_sql("SELECT tagsyncstatus, COUNT(tagsyncstatus) as statuscount
230+
$cachekey = 'tag_sync_status_summary';
231+
$cache = \cache::make('tool_objectfs', 'tagsummary');
232+
$cachedresult = $cache->get($cachekey);
233+
234+
if ($cachedresult !== false) {
235+
return $cachedresult;
236+
}
237+
238+
$result = $DB->get_records_sql("SELECT tagsyncstatus, COUNT(tagsyncstatus) as statuscount
231239
FROM {tool_objectfs_objects}
232240
GROUP BY tagsyncstatus");
241+
242+
$cache->set($cachekey, $result);
243+
244+
return $result;
233245
}
234246

235247
/**

db/caches.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Cache definitions for tool_objectfs
19+
*
20+
* @package tool_objectfs
21+
* @copyright Catalyst IT
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
defined('MOODLE_INTERNAL') || die();
26+
27+
$definitions = [
28+
'tagsummary' => [
29+
'mode' => cache_store::MODE_APPLICATION,
30+
'ttl' => 1800,
31+
'simplekeys' => true,
32+
'simpledata' => true,
33+
],
34+
];

db/upgrade.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,15 @@ function xmldb_tool_objectfs_upgrade($oldversion) {
223223
upgrade_plugin_savepoint(true, 2024120600, 'tool', 'objectfs');
224224
}
225225

226+
if ($oldversion < 2025071100) {
227+
$table = new xmldb_table('tool_objectfs_objects');
228+
$index = new xmldb_index('tagsyncstatus_idx', XMLDB_INDEX_NOTUNIQUE, ['tagsyncstatus']);
229+
if (!$dbman->index_exists($table, $index)) {
230+
$dbman->add_index($table, $index);
231+
}
232+
233+
upgrade_plugin_savepoint(true, 2025071100, 'tool', 'objectfs');
234+
}
235+
226236
return true;
227237
}

version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
defined('MOODLE_INTERNAL') || die();
2727

28-
$plugin->version = 2025040900; // The current plugin version (Date: YYYYMMDDXX).
28+
$plugin->version = 2025071100; // The current plugin version (Date: YYYYMMDDXX).
2929
$plugin->release = 2025040900; // Same as version.
3030
$plugin->requires = 2024042200; // Requires 4.4.
3131
$plugin->component = "tool_objectfs";

0 commit comments

Comments
 (0)