From d344018e1960fbc3805c0afed2eb8786dbb06ba6 Mon Sep 17 00:00:00 2001 From: marcus Date: Fri, 27 Jun 2008 15:46:37 +0000 Subject: Metastrings now keeps a record of strings it knows aren't present and so removes the need to futher look for them. Refs #101 git-svn-id: https://code.elgg.org/elgg/trunk@1189 36083f99-b078-4883-b0ff-0f9b5a30f544 --- engine/lib/metastrings.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'engine/lib/metastrings.php') diff --git a/engine/lib/metastrings.php b/engine/lib/metastrings.php index cf484b2d4..ef19df9e5 100644 --- a/engine/lib/metastrings.php +++ b/engine/lib/metastrings.php @@ -13,6 +13,8 @@ /** Cache metastrings for a page */ $METASTRINGS_CACHE = array(); + + $METASTRINGS_DEADNAME_CACHE = array(); /** * Return the meta string id for a given tag, or false. @@ -22,7 +24,7 @@ */ function get_metastring_id($string) { - global $CONFIG, $METASTRINGS_CACHE; + global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; $string = sanitise_string($string); $result = array_search($string, $METASTRINGS_CACHE); @@ -34,6 +36,10 @@ return $result; } + // See if we have previously looked for this and found nothing + if (in_array($string, $METASTRINGS_DEADNAME_CACHE)) + return false; + $row = get_data_row("SELECT * from {$CONFIG->dbprefix}metastrings where string='$string' limit 1"); if ($row) { $METASTRINGS_CACHE[$row->id] = $row->string; // Cache it @@ -43,6 +49,8 @@ return $row->id; } + else + $METASTRINGS_DEADNAME_CACHE[$string] = $string; return false; } @@ -90,7 +98,7 @@ */ function add_metastring($string) { - global $CONFIG, $METASTRINGS_CACHE; + global $CONFIG, $METASTRINGS_CACHE, $METASTRINGS_DEADNAME_CACHE; $sanstring = sanitise_string($string); @@ -98,8 +106,10 @@ if ($id) return $id; $result = insert_data("INSERT into {$CONFIG->dbprefix}metastrings (string) values ('$sanstring')"); - if ($result) + if ($result) { $METASTRINGS_CACHE[$result] = $string; + if (isset($METASTRINGS_DEADNAME_CACHE[$string])) unset($METASTRINGS_DEADNAME_CACHE[$string]); + } return $result; } -- cgit v1.2.3