aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/metastrings.php
diff options
context:
space:
mode:
authormarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-27 09:25:00 +0000
committermarcus <marcus@36083f99-b078-4883-b0ff-0f9b5a30f544>2008-06-27 09:25:00 +0000
commit6abb350a17931f139f3d4571e4c5a5fa4b0b1005 (patch)
tree664d1e0f223ca2b83439c0e92ece8ecd84a1c006 /engine/lib/metastrings.php
parent2d560e5f9e95f7fd71e1490cd13a0ae947d81c9b (diff)
downloadelgg-6abb350a17931f139f3d4571e4c5a5fa4b0b1005.tar.gz
elgg-6abb350a17931f139f3d4571e4c5a5fa4b0b1005.tar.bz2
Closes #86
git-svn-id: https://code.elgg.org/elgg/trunk@1158 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'engine/lib/metastrings.php')
-rw-r--r--engine/lib/metastrings.php41
1 files changed, 32 insertions, 9 deletions
diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php
index 74668ec81..5a91905e4 100644
--- a/engine/lib/metastrings.php
+++ b/engine/lib/metastrings.php
@@ -11,6 +11,9 @@
* @link http://elgg.org/
*/
+ /** Cache metastrings for a page */
+ $METASTRINGS_CACHE = array();
+
/**
* Return the meta string id for a given tag, or false.
*
@@ -19,13 +22,21 @@
*/
function get_metastring_id($string)
{
- global $CONFIG;
+ global $CONFIG, $METASTRINGS_CACHE;
$string = sanitise_string($string);
-
+ $result = array_search($string, $METASTRINGS_CACHE);
+ if ($result!==false)
+ return $result;
+
$row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where string='$string' limit 1");
- if ($row)
+ if ($row) {
+ $METASTRINGS_CACHE[$row->id] = $row->string; // Cache it
+ if ($CONFIG->debug)
+ error_log("Returning id for string {$row->string} from cache.");
+
return $row->id;
+ }
return false;
}
@@ -38,13 +49,21 @@
*/
function get_metastring($id) {
- global $CONFIG;
+ global $CONFIG, $METASTRINGS_CACHE;
- $id = (int) $id;
+ $id = (int) $id;
+
+ if (isset($METASTRINGS_CACHE[$id]))
+ return $METASTRINGS_CACHE[$id];
$row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where id='$id' limit 1");
- if ($row)
- return $row->string;
+ if ($row) {
+ $METASTRINGS_CACHE[$id] = $row->string; // Cache it
+ if ($CONFIG->debug)
+ error_log("Returning string {$row->string} from cache.");
+
+ return $row->string;
+ }
return false;
@@ -59,14 +78,18 @@
*/
function add_metastring($string)
{
- global $CONFIG;
+ global $CONFIG, $METASTRINGS_CACHE;
$sanstring = sanitise_string($string);
$id = get_metastring_id($string);
if ($id) return $id;
- return insert_data("INSERT into {$CONFIG->dbprefix}metastrings (string) values ('$sanstring')");
+ $result = insert_data("INSERT into {$CONFIG->dbprefix}metastrings (string) values ('$sanstring')");
+ if ($result)
+ $METASTRINGS_CACHE[$result] = $string;
+
+ return $result;
}
?> \ No newline at end of file