aboutsummaryrefslogtreecommitdiffstats
path: root/admin/include
diff options
context:
space:
mode:
authormistic100 <mistic@piwigo.org>2014-05-24 14:18:04 +0000
committermistic100 <mistic@piwigo.org>2014-05-24 14:18:04 +0000
commitfea2a4efd1ad085def7cf84cc444325d0815b62e (patch)
tree892dcb971d34efd7cbff6c31375448a09dfbe73b /admin/include
parent59f418f7986594895a2352e8895250069cff336a (diff)
feature 3077 : improve cache invalidation
- add "lastmodified" automatic field for categories, groups, users, tags and images tables - provide a "server key" to the client cache manager git-svn-id: http://piwigo.org/svn/trunk@28532 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin/include')
-rw-r--r--admin/include/functions.php61
1 files changed, 53 insertions, 8 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index 384189408..a3778f595 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -400,13 +400,8 @@ function delete_orphan_tags()
{
$orphan_tag_ids[] = $tag['id'];
}
-
- $query = '
-DELETE
- FROM '.TAGS_TABLE.'
- WHERE id IN ('.implode(',', $orphan_tag_ids).')
-;';
- pwg_query($query);
+
+ delete_tags($orphan_tag_ids);
}
}
@@ -2733,4 +2728,54 @@ function deltree($path, $trash_path=null)
}
}
-?> \ No newline at end of file
+/**
+ * Returns keys to identify the state of main tables. A key consists of the
+ * last modification timestamp and the total of items (separated by a _).
+ * Additionally returns the hash of root path.
+ * Used to invalidate LocalStorage cache on admin pages.
+ *
+ * @param string|string[] list of keys to retrieve (categories,groups,images,tags,users)
+ * @return string[]
+ */
+function get_admin_client_cache_keys($requested=array())
+{
+ $tables = array(
+ 'categories' => CATEGORIES_TABLE,
+ 'groups' => GROUPS_TABLE,
+ 'images' => IMAGES_TABLE,
+ 'tags' => TAGS_TABLE,
+ 'users' => USER_INFOS_TABLE
+ );
+
+ if (!is_array($requested))
+ {
+ $requested = array($requested);
+ }
+ if (empty($requested))
+ {
+ $requested = array_keys($tables);
+ }
+ else
+ {
+ $requested = array_intersect($requested, array_keys($tables));
+ }
+
+ $keys = array(
+ '_hash' => md5(get_absolute_root_url()),
+ );
+
+ foreach ($requested as $item)
+ {
+ $query = '
+SELECT CONCAT(
+ UNIX_TIMESTAMP(MAX(lastmodified)),
+ "_",
+ COUNT(*)
+ )
+ FROM '. $tables[$item] .'
+;';
+ list($keys[$item]) = pwg_db_fetch_row(pwg_query($query));
+ }
+
+ return $keys;
+} \ No newline at end of file