Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion classes/local/tag/tag_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,21 @@ public static function get_sync_status_string(int $tagsyncstatus): string {
*/
public static function get_tag_sync_status_summary(): array {
global $DB;
return $DB->get_records_sql("SELECT tagsyncstatus, COUNT(tagsyncstatus) as statuscount
$cachekey = 'tag_sync_status_summary';
$cache = \cache::make('tool_objectfs', 'tagsummary');
$cachedresult = $cache->get($cachekey);

if ($cachedresult !== false) {
return $cachedresult;
}

$result = $DB->get_records_sql("SELECT tagsyncstatus, COUNT(tagsyncstatus) as statuscount
FROM {tool_objectfs_objects}
GROUP BY tagsyncstatus");

$cache->set($cachekey, $result);

return $result;
}

/**
Expand Down
34 changes: 34 additions & 0 deletions db/caches.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Cache definitions for tool_objectfs
*
* @package tool_objectfs
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

$definitions = [
'tagsummary' => [
'mode' => cache_store::MODE_APPLICATION,
'ttl' => 1800,
'simplekeys' => true,
'simpledata' => true,
],
];
10 changes: 10 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,15 @@ function xmldb_tool_objectfs_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2024120600, 'tool', 'objectfs');
}

if ($oldversion < 2025071100) {
$table = new xmldb_table('tool_objectfs_objects');
$index = new xmldb_index('tagsyncstatus_idx', XMLDB_INDEX_NOTUNIQUE, ['tagsyncstatus']);
if (!$dbman->index_exists($table, $index)) {
$dbman->add_index($table, $index);
}

upgrade_plugin_savepoint(true, 2025071100, 'tool', 'objectfs');
}

return true;
}
27 changes: 27 additions & 0 deletions tests/check/tagging_sync_status_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,31 @@ public function test_get_result_warning() {
$check = new tagging_sync_status();
$this->assertEquals(result::WARNING, $check->get_result()->get_status());
}

/**
* Test caching
*/
public function test_tag_sync_status_summary_caching() {
global $DB;
$this->enable_filesystem_and_set_tagging(true);

$cache = \cache::make('tool_objectfs', 'tagsummary');
$cache->delete('tag_sync_status_summary');

$this->assertEquals($cache->get('tag_sync_status_summary'), false);

// Test: First call should hit DB, second should use cache.
$before = $DB->perf_get_queries();
$result1 = tag_manager::get_tag_sync_status_summary();
$after1 = $DB->perf_get_queries();

$this->assertNotEquals($cache->get('tag_sync_status_summary'), false);

$result2 = tag_manager::get_tag_sync_status_summary();
$after2 = $DB->perf_get_queries();

$this->assertGreaterThan($before, $after1, 'First call should hit DB');
$this->assertEquals($after1, $after2, 'Second call should use cache');
$this->assertEquals($result1, $result2, 'Cached and DB results should match');
}
}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

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

$plugin->version = 2025040900; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2025040900; // Same as version.
$plugin->version = 2025071100; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2025071100; // Same as version.
$plugin->requires = 2024042200; // Requires 4.4.
$plugin->component = "tool_objectfs";
$plugin->maturity = MATURITY_STABLE;
Expand Down
Loading