r91534 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91533‎ | r91534 | r91535 >
Date:08:16, 6 July 2011
Author:mkroetzsch
Status:deferred
Tags:
Comment:
reworked ID caching for clarity and correctness
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStore2IdCache.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -32,8 +32,8 @@
3333 */
3434 class SMWSQLStore2 extends SMWStore {
3535
36 - /// Cache for SMW IDs, indexed by string keys
37 - protected $m_ids = array();
 36+ /// Cache for SMW IDs
 37+ protected $m_idCache;
3838
3939 /// Cache for SMWSemanticData objects, indexed by SMW ID
4040 protected $m_semdata = array();
@@ -109,6 +109,10 @@
110110 SMWDataItem::TYPE_PROPERTY => 'smw_atts2' // unlikely to occur as value of any property
111111 );
112112
 113+ public function __construct() {
 114+ $this->m_idCache = new SMWSqlStore2IdCache( wfGetDB( DB_SLAVE ) );
 115+ }
 116+
113117 ///// Reading methods /////
114118
115119 public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) {
@@ -119,7 +123,8 @@
120124
121125 // *** Find out if this subject exists ***//
122126 $sortkey = '';
123 - $sid = $this->getSMWPageIDandSort( $subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), $sortkey, true );
 127+ $sid = $this->getSMWPageIDandSort( $subject->getDBkey(), $subject->getNamespace(),
 128+ $subject->getInterwiki(), $subject->getSubobjectName(), $sortkey, true );
124129 if ( $sid == 0 ) { // no data, safe our time
125130 /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects"
126131 self::$in_getSemanticData--;
@@ -907,10 +912,16 @@
908913 // If equality support is off, then this simple move
909914 // does too much; fall back to general case below.
910915 if ( $sid != 0 ) { // change id entry to refer to the new title
911 - // Note that is also changes the reference for internal objects (subobjects)
912 - $db->update( 'smw_ids',
913 - array( 'smw_title' => $newtitle->getDBkey(), 'smw_namespace' => $newtitle->getNamespace(), 'smw_iw' => '' ),
914 - array( 'smw_title' => $oldtitle->getDBkey(), 'smw_namespace' => $oldtitle->getNamespace(), 'smw_iw' => '' ), __METHOD__ );
 916+ // Note that this also changes the reference for internal objects (subobjects)
 917+ $db->update( 'smw_ids', array( 'smw_title' => $newtitle->getDBkey(),
 918+ 'smw_namespace' => $newtitle->getNamespace(), 'smw_iw' => '' ),
 919+ array( 'smw_title' => $oldtitle->getDBkey(),
 920+ 'smw_namespace' => $oldtitle->getNamespace(), 'smw_iw' => '' ),
 921+ __METHOD__ );
 922+ $this->m_idCache->moveSubobjects( $oldtitle->getDBkey(), $oldtitle->getNamespace(),
 923+ $newtitle->getDBkey(), $newtitle->getNamespace() );
 924+ $this->m_idCache->setId( $oldtitle->getDBkey(), $oldtitle->getNamespace(), '', '', 0 );
 925+ $this->m_idCache->setId( $newtitle->getDBkey(), $newtitle->getNamespace(), '', '', $sid );
915926 } else { // make new (target) id for use in redirect table
916927 $sid = $this->makeSMWPageID( $newtitle->getDBkey(), $newtitle->getNamespace(), '', '' );
917928 } // at this point, $sid is the id of the target page (according to smw_ids)
@@ -921,11 +932,7 @@
922933 's_namespace' => $oldtitle->getNamespace(),
923934 'o_id' => $sid ),
924935 __METHOD__ );
925 - // update caches:
926 - $this->m_ids[' ' . $oldtitle->getNamespace() . ' ' . $oldtitle->getDBkey() . ' C'] = $sid;
927 - // $this->m_ids[" " . $oldtitle->getNamespace() . " " . $oldtitle->getDBkey() . " -"] = Already OK after makeSMWPageID above
928 - $this->m_ids[' ' . $newtitle->getNamespace() . ' ' . $newtitle->getDBkey() . ' C'] = $sid;
929 - $this->m_ids[' ' . $newtitle->getNamespace() . ' ' . $newtitle->getDBkey() . ' -'] = $sid;
 936+
930937 /// NOTE: there is the (bad) case that the moved page is a redirect. As chains of
931938 /// redirects are not supported by MW or SMW, the above is maximally correct in this case too.
932939 /// NOTE: this temporarily leaves existing redirects to oldtitle point to newtitle as well, which
@@ -943,14 +950,10 @@
944951
945952 // Move all data of old title to new position:
946953 if ( $sid != 0 ) {
947 - $this->changeSMWPageID( $sid, $tid, $oldtitle->getNamespace(), $newtitle->getNamespace(), true, false );
 954+ $this->changeSMWPageID( $sid, $tid, $oldtitle->getNamespace(),
 955+ $newtitle->getNamespace(), true, false );
948956 }
949957
950 - // Write a redirect from old title to new one:
951 - // (this also updates references in other tables as needed.)
952 - /// TODO: may not be optimal for the standard case that newtitle existed and redirected to oldtitle (PERFORMANCE)
953 - $this->updateRedirects( $oldtitle->getDBkey(), $oldtitle->getNamespace(), $newtitle->getDBkey(), $newtitle->getNamespace() );
954 -
955958 // Associate internal objects (subobjects) with the new title:
956959 $table = $db->tableName( 'smw_ids' );
957960 $values = array( 'smw_title' => $newtitle->getDBkey(), 'smw_namespace' => $newtitle->getNamespace(), 'smw_iw' => '' );
@@ -965,6 +968,13 @@
966969 // array( 'smw_title' => $newtitle->getDBkey(), 'smw_namespace' => $newtitle->getNamespace(), 'smw_iw' => '' ),
967970 // array( 'smw_title' => $oldtitle->getDBkey(), 'smw_namespace' => $oldtitle->getNamespace(), 'smw_iw' => '', 'smw_subobject!' => array( '' ) ), // array() needed for ! to work
968971 // __METHOD__ );
 972+ $this->m_idCache->moveSubobjects( $oldtitle->getDBkey(), $oldtitle->getNamespace(),
 973+ $newtitle->getDBkey(), $newtitle->getNamespace() );
 974+
 975+ // Write a redirect from old title to new one:
 976+ // (this also updates references in other tables as needed.)
 977+ /// TODO: may not be optimal for the standard case that newtitle existed and redirected to oldtitle (PERFORMANCE)
 978+ $this->updateRedirects( $oldtitle->getDBkey(), $oldtitle->getNamespace(), $newtitle->getDBkey(), $newtitle->getNamespace() );
969979 }
970980
971981 wfProfileOut( "SMWSQLStore2::changeTitle (SMW)" );
@@ -1281,7 +1291,7 @@
12821292 $reportTo
12831293 );
12841294
1285 - SMWSQLHelpers::setupIndex( 'smw_ids', array( 'smw_id', 'smw_title,smw_namespace,smw_iw,smw_subobject', 'smw_sortkey' ), $db );
 1295+ SMWSQLHelpers::setupIndex( 'smw_ids', array( 'smw_id', 'smw_title,smw_namespace,smw_iw', 'smw_title,smw_namespace,smw_iw,smw_subobject', 'smw_sortkey' ), $db );
12861296
12871297 // Set up concept cache: member elements (s)->concepts (o)
12881298 SMWSQLHelpers::setupTable(
@@ -1908,98 +1918,74 @@
19091919 * returned.
19101920 */
19111921 public function getSMWPageID( $title, $namespace, $iw, $subobjectName, $canonical = true ) {
1912 - $sort = '';
1913 - return $this->getSMWPageIDandSort( $title, $namespace, $iw, $subobjectName, $sort, $canonical );
 1922+ global $smwgQEqualitySupport;
 1923+
 1924+ $id = $this->m_idCache->getId( $title, $namespace, $iw, $subobjectName );
 1925+ if ( $id == 0 && $smwgQEqualitySupport != SMW_EQ_NONE
 1926+ && $subobjectName == '' && $iw == '' ) {
 1927+ $iw = SMW_SQL2_SMWREDIIW;
 1928+ $id = $this->m_idCache->getId( $title, $namespace, SMW_SQL2_SMWREDIIW, $subobjectName );
 1929+ }
 1930+
 1931+ if ( $id == 0 || !$canonical || $iw != SMW_SQL2_SMWREDIIW ) {
 1932+ return $id;
 1933+ } else {
 1934+ $rediId = $this->getRedirectId( $title, $namespace );
 1935+ return $rediId != 0 ? $rediId : $id; // fallback for inconsistent redirect info
 1936+ }
19141937 }
19151938
19161939 /**
19171940 * Like getSMWPageID(), but also sets the Call-By-Ref parameter $sort to
19181941 * the current sortkey.
1919 - * @todo Ensuring that properties redirect to properties only should not be done here.
1920 - * @todo Centralise creation of id cache keys, and make sure non-local pages have only one key
1921 - * (no need to distinguish canonical/non-canonical in this case).
19221942 */
19231943 public function getSMWPageIDandSort( $title, $namespace, $iw, $subobjectName, &$sort, $canonical ) {
1924 - global $smwgQEqualitySupport;
1925 -
19261944 wfProfileIn( 'SMWSQLStore2::getSMWPageID (SMW)' );
19271945
1928 - $ckey = "$iw $namespace $title $subobjectName C";
1929 - $nkey = "$iw $namespace $title $subobjectName -";
1930 - $key = ( $canonical ? $ckey : $nkey );
 1946+ global $smwgQEqualitySupport;
19311947
1932 - if ( array_key_exists( $key, $this->m_ids ) ) {
1933 - wfProfileOut( 'SMWSQLStore2::getSMWPageID (SMW)' );
1934 - return $this->m_ids[$key];
1935 - }
1936 -
1937 - if ( count( $this->m_ids ) > 1500 ) { // prevent memory leak in very long PHP runs
1938 - $this->m_ids = array();
1939 - }
1940 -
19411948 $db = wfGetDB( DB_SLAVE );
1942 - $id = 0;
19431949
19441950 if ( $iw != '' ) { // external page; no need to think about redirects
1945 - $res = $db->select(
1946 - 'smw_ids',
1947 - array( 'smw_id', 'smw_sortkey' ),
1948 - array( 'smw_title' => $title, 'smw_namespace' => $namespace, 'smw_iw' => $iw, 'smw_subobject' => $subobjectName ),
1949 - 'SMW::getSMWPageID', array( 'LIMIT' => 1 )
1950 - );
1951 - $row = $db->fetchObject( $res );
1952 - if ( $row ) {
1953 - $id = $row->smw_id;
1954 - $sort = $row->smw_sortkey;
1955 - }
 1951+ $iwCond = 'smw_iw=' . $db->addQuotes( $iw );
 1952+ } else {
 1953+ $iwCond = '(smw_iw=' . $db->addQuotes( '' ) .
 1954+ ' OR smw_iw=' . $db->addQuotes( SMW_SQL2_SMWREDIIW ) . ')';
 1955+ }
19561956
1957 - $this->m_ids[ $canonical ? $nkey : $ckey ] = $id; // unique id, make sure cache for canonical+non-cacnonical gets filled: this line fills the cache that is not $key!
1958 - } else { // check for potential redirects also
1959 - $res = $db->select( 'smw_ids', array( 'smw_id', 'smw_iw', 'smw_sortkey' ),
1960 - 'smw_title=' . $db->addQuotes( $title ) .
1961 - ' AND smw_namespace=' . $db->addQuotes( $namespace ) .
1962 - ' AND (smw_iw=' . $db->addQuotes( '' ) .
1963 - ' OR smw_iw=' . $db->addQuotes( SMW_SQL2_SMWREDIIW ) . ')' .
1964 - ' AND smw_subobject=' . $db->addQuotes( $subobjectName ),
1965 - 'SMW::getSMWPageID', array( 'LIMIT' => 1 ) );
1966 - $row = $db->fetchObject( $res );
 1957+ $row = $db->selectRow( 'smw_ids', array( 'smw_id', 'smw_iw', 'smw_sortkey' ),
 1958+ 'smw_title=' . $db->addQuotes( $title ) .
 1959+ ' AND smw_namespace=' . $db->addQuotes( $namespace ) .
 1960+ " AND $iwCond AND smw_subobject=" . $db->addQuotes( $subobjectName ),
 1961+ __METHOD__ );
19671962
1968 - if ( $row ) {
1969 - $id = $row->smw_id; // set id in any case, the below check for properties will use even the redirect id in emergency
1970 - $sort = $row->smw_sortkey;
 1963+ if ( $row !== false ) {
 1964+ $sort = $row->smw_sortkey;
 1965+ $this->m_idCache->setId( $title, $namespace, $row->smw_iw, $subobjectName, $row->smw_id );
19711966
1972 - if ( ( $row->smw_iw == '' ) ) { // the id found is unique (canonical and non-canonical); fill cache also for the case *not* asked for
1973 - $this->m_ids[ $canonical ? $nkey : $ckey ] = $id; // (the other cache is filled below)
1974 - } elseif ( $canonical && ( $subobjectName == '' ) && ( $smwgQEqualitySupport != SMW_EQ_NONE ) ) { // check for redirect alias
1975 - if ( $namespace == SMW_NS_PROPERTY ) { // redirect properties only to properties
1976 - ///TODO: Shouldn't this condition be ensured during writing?
1977 - $res2 = $db->select( array( 'smw_redi2', 'smw_ids' ), 'o_id',
1978 - 'o_id=smw_id AND smw_namespace=s_namespace AND s_title=' . $db->addQuotes( $title ) .
1979 - ' AND s_namespace=' . $db->addQuotes( $namespace ), 'SMW::getSMWPageID', array( 'LIMIT' => 1 ) );
1980 - } else {
1981 - $res2 = $db->select( 'smw_redi2', 'o_id',
1982 - 's_title=' . $db->addQuotes( $title ) . ' AND s_namespace=' . $db->addQuotes( $namespace ),
1983 - 'SMW::getSMWPageID', array( 'LIMIT' => 1 ) );
1984 - }
1985 - $row = $db->fetchObject( $res2 );
1986 - if ( $row ) {
1987 - $id = $row->o_id;
1988 - }
1989 -
1990 - $db->freeResult( $res2 );
1991 - }
 1967+ if ( $row->smw_iw == SMW_SQL2_SMWREDIIW && $canonical &&
 1968+ $subobjectName == '' && $smwgQEqualitySupport != SMW_EQ_NONE ) {
 1969+ $id = $this->getRedirectId( $title, $namespace );
 1970+ $this->m_idCache->setId( $title, $namespace, $iw, $subobjectName, 0 );
 1971+ } else {
 1972+ $id = $row->smw_id;
19921973 }
1993 -
 1974+ } else {
 1975+ $id = 0;
 1976+ $this->m_idCache->setId( $title, $namespace, $iw, $subobjectName, 0 );
19941977 }
19951978
1996 - $db->freeResult( $res );
1997 -
1998 - $this->m_ids[$key] = $id;
19991979 wfProfileOut( 'SMWSQLStore2::getSMWPageID (SMW)' );
2000 -
20011980 return $id;
20021981 }
20031982
 1983+ public function getRedirectId( $title, $namespace ) {
 1984+ $db = wfGetDB( DB_SLAVE );
 1985+ $row = $db->selectRow( 'smw_redi2', 'o_id',
 1986+ array( 's_title' => $title, 's_namespace' => $namespace ), __METHOD__ );
 1987+ return ( $row === false ) ? 0 : $row->o_id;
 1988+ }
 1989+
20041990 /**
20051991 * Find the numeric ID used for the page of the given title and namespace.
20061992 * If $canonical is set to true, redirects are taken into account to find
@@ -2030,23 +2016,18 @@
20312017 'smw_subobject' => $subobjectName,
20322018 'smw_sortkey' => $sortkey
20332019 ),
2034 - 'SMW::makeSMWPageID'
 2020+ __METHOD__
20352021 );
20362022
20372023 $id = $db->insertId();
2038 - $this->m_ids["$iw $namespace $title $subobjectName -"] = $id; // fill that cache, even if canonical was given
2039 -
2040 - // This ID is also authorative for the canonical version.
2041 - // This is always the case: if $canonical===false and $id===0, then there is no redi-entry in
2042 - // smw_ids either, hence the object just did not exist at all.
2043 - $this->m_ids["$iw $namespace $title $subobjectName C"] = $id;
 2024+
 2025+ $this->m_idCache->setId( $title, $namespace, $iw, $subobjectName, $id );
20442026 } elseif ( ( $sortkey != '' ) && ( $sortkey != $oldsort ) ) {
20452027 $db = wfGetDB( DB_MASTER );
2046 - $db->update( 'smw_ids', array( 'smw_sortkey' => $sortkey ), array( 'smw_id' => $id ), 'SMW::makeSMWPageID' );
 2028+ $db->update( 'smw_ids', array( 'smw_sortkey' => $sortkey ), array( 'smw_id' => $id ), __METHOD__ );
20472029 }
20482030
20492031 wfProfileOut( 'SMWSQLStore2::makeSMWPageID (SMW)' );
2050 -
20512032 return $id;
20522033 }
20532034
@@ -2096,18 +2077,7 @@
20972078 * whether the given ID is canonical or not.
20982079 */
20992080 public function cacheSMWPageID( $id, $title, $namespace, $iw, $subobjectName ) {
2100 - $ckey = "$iw $namespace $title $subobjectName C";
2101 - $nkey = "$iw $namespace $title $subobjectName -";
2102 -
2103 - if ( count( $this->m_ids ) > 1500 ) { // prevent memory leak in very long PHP runs
2104 - $this->m_ids = array();
2105 - }
2106 -
2107 - $this->m_ids[$nkey] = $id;
2108 -
2109 - if ( $iw != SMW_SQL2_SMWREDIIW ) {
2110 - $this->m_ids[$ckey] = $id;
2111 - }
 2081+ $this->m_idCache->setId( $title, $namespace, $iw, $subobjectName, $id );
21122082 }
21132083
21142084 /**
@@ -2117,17 +2087,11 @@
21182088 * moved consistently in all relevant tables. Whatever currently occupies
21192089 * the target id will be ignored (it should be ensured that nothing is
21202090 * moved to an id that is still in use somewhere).
2121 - * @note This page does not update any caches. If relevant, this needs to
2122 - * be effected by the caller.
21232091 */
21242092 protected function moveSMWPageID( $curid, $targetid = 0 ) {
21252093 $db = wfGetDB( DB_MASTER );
21262094
2127 - $row = $db->selectRow(
2128 - 'smw_ids',
2129 - array( 'smw_id', 'smw_namespace', 'smw_title', 'smw_iw', 'smw_subobject', 'smw_sortkey' ),
2130 - array( 'smw_id' => $curid ), 'SMWSQLStore2::moveSMWPageID'
2131 - );
 2095+ $row = $db->selectRow( 'smw_ids', '*', array( 'smw_id' => $curid ), __METHOD__ );
21322096
21332097 if ( $row === false ) return; // no id at current position, ignore
21342098
@@ -2142,9 +2106,8 @@
21432107 'smw_subobject' => $row->smw_subobject,
21442108 'smw_sortkey' => $row->smw_sortkey
21452109 ),
2146 - 'SMW::moveSMWPageID'
 2110+ __METHOD__
21472111 );
2148 -
21492112 $targetid = $db->insertId();
21502113 } else { // change to given id
21512114 $db->insert( 'smw_ids',
@@ -2155,11 +2118,15 @@
21562119 'smw_subobject' => $row->smw_subobject,
21572120 'smw_sortkey' => $row->smw_sortkey
21582121 ),
2159 - 'SMW::moveSMWPageID'
 2122+ __METHOD__
21602123 );
21612124 }
21622125
21632126 $db->delete( 'smw_ids', array( 'smw_id' => $curid ), 'SMWSQLStore2::moveSMWPageID' );
 2127+
 2128+ $this->m_idCache->setId( $row->smw_title, $row->smw_namespace, $row->smw_iw,
 2129+ $row->smw_subobject, $targetid );
 2130+
21642131 $this->changeSMWPageID( $curid, $targetid, $row->smw_namespace, $row->smw_namespace );
21652132 }
21662133
@@ -2257,7 +2224,7 @@
22582225 }
22592226
22602227 // also find subobjects used by this ID ...
2261 - $res = $db->select( 'smw_ids', 'smw_id',
 2228+ $res = $db->select( 'smw_ids', '*',
22622229 'smw_title = ' . $db->addQuotes( $subject->getDBkey() ) . ' AND ' .
22632230 'smw_namespace = ' . $db->addQuotes( $subject->getNamespace() ) . ' AND ' .
22642231 'smw_iw = ' . $db->addQuotes( $subject->getInterwiki() ) . ' AND ' .
@@ -2273,6 +2240,8 @@
22742241 // ... and delete them as well
22752242 foreach ( $res as $row ) {
22762243 $subobjects[] = $row->smw_id;
 2244+ $this->m_idCache->setId( $row->smw_title, $row->smw_namespace,
 2245+ $row->smw_iw, $row->smw_subobject, 0 ); // deleted below
22772246 foreach ( self::getPropertyTables() as $proptable ) {
22782247 if ( $proptable->idsubject ) {
22792248 $db->delete( $proptable->name, array( 's_id' => $row->smw_id ), __METHOD__ );
@@ -2409,25 +2378,24 @@
24102379 // mark subject as redirect (if it was no redirect before)
24112380 if ( $sid == 0 ) { // every redirect page must have an ID
24122381 $sid = $this->makeSMWPageID( $subject_t, $subject_ns,
2413 - SMW_SQL2_SMWREDIIW, '', false );
 2382+ SMW_SQL2_SMWREDIIW, '', false );
24142383 } else {
24152384 $db->update( 'smw_ids', array( 'smw_iw' => SMW_SQL2_SMWREDIIW ),
2416 - array( 'smw_id' => $sid ), __METHOD__ );
 2385+ array( 'smw_id' => $sid ), __METHOD__ );
 2386+ $this->m_idCache->setId( $subject_t, $subject_ns, '', '', 0 );
 2387+ $this->m_idCache->setId( $subject_t, $subject_ns, SMW_SQL2_SMWREDIIW, '', $sid );
24172388 }
24182389 }
24192390
24202391 $db->insert( 'smw_redi2', array( 's_title' => $subject_t,
2421 - 's_namespace' => $subject_ns,
2422 - 'o_id' => $new_tid ), __METHOD__ );
2423 - $this->m_ids[" $subject_ns $subject_t C"] = $new_tid;
 2392+ 's_namespace' => $subject_ns, 'o_id' => $new_tid ), __METHOD__ );
24242393 } else { // delete old redirect
24252394 // This case implies $old_tid != 0 (or we would have new_tid == old_tid above).
24262395 // Therefore $subject had a redirect, and it must also have an ID.
24272396 // This shows that $sid != 0 here.
2428 - $this->m_ids[" $subject_ns $subject_t C"] = $sid;
2429 -
24302397 if ( $smwgQEqualitySupport != SMW_EQ_NONE ) { // mark subject as non-redirect
24312398 $db->update( 'smw_ids', array( 'smw_iw' => '' ), array( 'smw_id' => $sid ), __METHOD__ );
 2399+ $this->m_idCache->setId( $subject_t, $subject_ns, '', '', $sid );
24322400 }
24332401 }
24342402
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStore2IdCache.php
@@ -0,0 +1,93 @@
 2+<?php
 3+/**
 4+ * The class in this file acts as an in-memory cache for managing object ids in
 5+ * SMWSQLStore2.
 6+ *
 7+ * @file
 8+ * @ingroup SMWStore
 9+ *
 10+ * @author Markus Krötzsch
 11+ */
 12+
 13+
 14+/**
 15+ * An in-memory cache for managing object ids in SMWSQLStore2.
 16+ *
 17+ * @since 1.6
 18+ *
 19+ * @ingroup SMWStore
 20+ */
 21+class SMWSqlStore2IdCache {
 22+ protected $m_db;
 23+ protected $m_data = array();
 24+
 25+ /**
 26+ * Constructor.
 27+ *
 28+ * @param $tableName string name of the table that is buffered
 29+ *
 30+ * @param $db Database handler
 31+ */
 32+ public function __construct( DatabaseType $db ) {
 33+ $this->m_db = $db;
 34+ }
 35+
 36+ public function getId( $title, $namespace, $interwiki, $subobject ) {
 37+ $hashKey = self::getHashKey( $title, $namespace, $interwiki, $subobject );
 38+ if ( array_key_exists( $hashKey, $this->m_data ) ) {
 39+ return $this->m_data[$hashKey];
 40+ } else {
 41+ $condition = array( 'smw_title' => $title,
 42+ 'smw_namespace' => $namespace,
 43+ 'smw_iw' => $interwiki,
 44+ 'smw_subobject' => $subobject );
 45+ $row = $this->m_db->selectRow( 'smw_ids', 'smw_id', $condition, __METHOD__);
 46+
 47+ if ( $row !== false ) {
 48+ $this->m_data[$hashKey] = $row->smw_id;
 49+ return $row->smw_id;
 50+ } else {
 51+ $index->data[$hashKey] = 0;
 52+ return 0;
 53+ }
 54+ }
 55+ }
 56+
 57+ public function getCachedId( $title, $namespace, $interwiki, $subobject ) {
 58+ $hashKey = self::getHashKey( $title, $namespace, $interwiki, $subobject );
 59+ if ( array_key_exists( $hashKey, $this->m_data ) ) {
 60+ return $this->m_data[$hashKey];
 61+ } else {
 62+ return false;
 63+ }
 64+ }
 65+
 66+ public function setId( $title, $namespace, $interwiki, $subobject, $id ) {
 67+ $hashKey = self::getHashKey( $title, $namespace, $interwiki, $subobject );
 68+ $this->m_data[$hashKey] = $id;
 69+ if ( $interwiki == SMW_SQL2_SMWREDIIW ) {
 70+ $hashKey = self::getHashKey( $title, $namespace, '', $subobject );
 71+ $this->m_data[$hashKey] = 0;
 72+ } // could do this for $interwiki == '' too, but the SMW_SQL2_SMWREDIIW would be useless
 73+ }
 74+
 75+ public function deleteId( $title, $namespace, $interwiki, $subobject ) {
 76+ $hashKey = self::getHashKey( $title, $namespace, $interwiki, $subobject );
 77+ unset( $this->m_data[$hashKey] );
 78+ }
 79+
 80+ public function moveSubobjects( $oldtitle, $oldnamespace, $newtitle, $newnamespace ) {
 81+ // Currently we have no way to change title and namespace across all entries.
 82+ // Best we can do is clear the cache to avoid wrong hits:
 83+ $this->clear();
 84+ }
 85+
 86+ public function clear() {
 87+ $this->m_data = array();
 88+ }
 89+
 90+ protected static function getHashKey( $title, $namespace, $interwiki, $subobject ) {
 91+ return "$title#$namespace#$interwiki#$subobject";
 92+ }
 93+
 94+}
\ No newline at end of file
Property changes on: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SqlStore2IdCache.php
___________________________________________________________________
Added: svn:eol-style
195 + native