Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php |
— | — | @@ -32,8 +32,8 @@ |
33 | 33 | */ |
34 | 34 | class SMWSQLStore2 extends SMWStore { |
35 | 35 | |
36 | | - /// Cache for SMW IDs, indexed by string keys |
37 | | - protected $m_ids = array(); |
| 36 | + /// Cache for SMW IDs |
| 37 | + protected $m_idCache; |
38 | 38 | |
39 | 39 | /// Cache for SMWSemanticData objects, indexed by SMW ID |
40 | 40 | protected $m_semdata = array(); |
— | — | @@ -109,6 +109,10 @@ |
110 | 110 | SMWDataItem::TYPE_PROPERTY => 'smw_atts2' // unlikely to occur as value of any property |
111 | 111 | ); |
112 | 112 | |
| 113 | + public function __construct() { |
| 114 | + $this->m_idCache = new SMWSqlStore2IdCache( wfGetDB( DB_SLAVE ) ); |
| 115 | + } |
| 116 | + |
113 | 117 | ///// Reading methods ///// |
114 | 118 | |
115 | 119 | public function getSemanticData( SMWDIWikiPage $subject, $filter = false ) { |
— | — | @@ -119,7 +123,8 @@ |
120 | 124 | |
121 | 125 | // *** Find out if this subject exists ***// |
122 | 126 | $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 ); |
124 | 129 | if ( $sid == 0 ) { // no data, safe our time |
125 | 130 | /// NOTE: we consider redirects for getting $sid, so $sid == 0 also means "no redirects" |
126 | 131 | self::$in_getSemanticData--; |
— | — | @@ -907,10 +912,16 @@ |
908 | 913 | // If equality support is off, then this simple move |
909 | 914 | // does too much; fall back to general case below. |
910 | 915 | 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 ); |
915 | 926 | } else { // make new (target) id for use in redirect table |
916 | 927 | $sid = $this->makeSMWPageID( $newtitle->getDBkey(), $newtitle->getNamespace(), '', '' ); |
917 | 928 | } // at this point, $sid is the id of the target page (according to smw_ids) |
— | — | @@ -921,11 +932,7 @@ |
922 | 933 | 's_namespace' => $oldtitle->getNamespace(), |
923 | 934 | 'o_id' => $sid ), |
924 | 935 | __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 | + |
930 | 937 | /// NOTE: there is the (bad) case that the moved page is a redirect. As chains of |
931 | 938 | /// redirects are not supported by MW or SMW, the above is maximally correct in this case too. |
932 | 939 | /// NOTE: this temporarily leaves existing redirects to oldtitle point to newtitle as well, which |
— | — | @@ -943,14 +950,10 @@ |
944 | 951 | |
945 | 952 | // Move all data of old title to new position: |
946 | 953 | 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 ); |
948 | 956 | } |
949 | 957 | |
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 | | - |
955 | 958 | // Associate internal objects (subobjects) with the new title: |
956 | 959 | $table = $db->tableName( 'smw_ids' ); |
957 | 960 | $values = array( 'smw_title' => $newtitle->getDBkey(), 'smw_namespace' => $newtitle->getNamespace(), 'smw_iw' => '' ); |
— | — | @@ -965,6 +968,13 @@ |
966 | 969 | // array( 'smw_title' => $newtitle->getDBkey(), 'smw_namespace' => $newtitle->getNamespace(), 'smw_iw' => '' ), |
967 | 970 | // array( 'smw_title' => $oldtitle->getDBkey(), 'smw_namespace' => $oldtitle->getNamespace(), 'smw_iw' => '', 'smw_subobject!' => array( '' ) ), // array() needed for ! to work |
968 | 971 | // __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() ); |
969 | 979 | } |
970 | 980 | |
971 | 981 | wfProfileOut( "SMWSQLStore2::changeTitle (SMW)" ); |
— | — | @@ -1281,7 +1291,7 @@ |
1282 | 1292 | $reportTo |
1283 | 1293 | ); |
1284 | 1294 | |
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 ); |
1286 | 1296 | |
1287 | 1297 | // Set up concept cache: member elements (s)->concepts (o) |
1288 | 1298 | SMWSQLHelpers::setupTable( |
— | — | @@ -1908,98 +1918,74 @@ |
1909 | 1919 | * returned. |
1910 | 1920 | */ |
1911 | 1921 | 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 | + } |
1914 | 1937 | } |
1915 | 1938 | |
1916 | 1939 | /** |
1917 | 1940 | * Like getSMWPageID(), but also sets the Call-By-Ref parameter $sort to |
1918 | 1941 | * 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). |
1922 | 1942 | */ |
1923 | 1943 | public function getSMWPageIDandSort( $title, $namespace, $iw, $subobjectName, &$sort, $canonical ) { |
1924 | | - global $smwgQEqualitySupport; |
1925 | | - |
1926 | 1944 | wfProfileIn( 'SMWSQLStore2::getSMWPageID (SMW)' ); |
1927 | 1945 | |
1928 | | - $ckey = "$iw $namespace $title $subobjectName C"; |
1929 | | - $nkey = "$iw $namespace $title $subobjectName -"; |
1930 | | - $key = ( $canonical ? $ckey : $nkey ); |
| 1946 | + global $smwgQEqualitySupport; |
1931 | 1947 | |
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 | | - |
1941 | 1948 | $db = wfGetDB( DB_SLAVE ); |
1942 | | - $id = 0; |
1943 | 1949 | |
1944 | 1950 | 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 | + } |
1956 | 1956 | |
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__ ); |
1967 | 1962 | |
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 ); |
1971 | 1966 | |
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; |
1992 | 1973 | } |
1993 | | - |
| 1974 | + } else { |
| 1975 | + $id = 0; |
| 1976 | + $this->m_idCache->setId( $title, $namespace, $iw, $subobjectName, 0 ); |
1994 | 1977 | } |
1995 | 1978 | |
1996 | | - $db->freeResult( $res ); |
1997 | | - |
1998 | | - $this->m_ids[$key] = $id; |
1999 | 1979 | wfProfileOut( 'SMWSQLStore2::getSMWPageID (SMW)' ); |
2000 | | - |
2001 | 1980 | return $id; |
2002 | 1981 | } |
2003 | 1982 | |
| 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 | + |
2004 | 1990 | /** |
2005 | 1991 | * Find the numeric ID used for the page of the given title and namespace. |
2006 | 1992 | * If $canonical is set to true, redirects are taken into account to find |
— | — | @@ -2030,23 +2016,18 @@ |
2031 | 2017 | 'smw_subobject' => $subobjectName, |
2032 | 2018 | 'smw_sortkey' => $sortkey |
2033 | 2019 | ), |
2034 | | - 'SMW::makeSMWPageID' |
| 2020 | + __METHOD__ |
2035 | 2021 | ); |
2036 | 2022 | |
2037 | 2023 | $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 ); |
2044 | 2026 | } elseif ( ( $sortkey != '' ) && ( $sortkey != $oldsort ) ) { |
2045 | 2027 | $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__ ); |
2047 | 2029 | } |
2048 | 2030 | |
2049 | 2031 | wfProfileOut( 'SMWSQLStore2::makeSMWPageID (SMW)' ); |
2050 | | - |
2051 | 2032 | return $id; |
2052 | 2033 | } |
2053 | 2034 | |
— | — | @@ -2096,18 +2077,7 @@ |
2097 | 2078 | * whether the given ID is canonical or not. |
2098 | 2079 | */ |
2099 | 2080 | 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 ); |
2112 | 2082 | } |
2113 | 2083 | |
2114 | 2084 | /** |
— | — | @@ -2117,17 +2087,11 @@ |
2118 | 2088 | * moved consistently in all relevant tables. Whatever currently occupies |
2119 | 2089 | * the target id will be ignored (it should be ensured that nothing is |
2120 | 2090 | * 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. |
2123 | 2091 | */ |
2124 | 2092 | protected function moveSMWPageID( $curid, $targetid = 0 ) { |
2125 | 2093 | $db = wfGetDB( DB_MASTER ); |
2126 | 2094 | |
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__ ); |
2132 | 2096 | |
2133 | 2097 | if ( $row === false ) return; // no id at current position, ignore |
2134 | 2098 | |
— | — | @@ -2142,9 +2106,8 @@ |
2143 | 2107 | 'smw_subobject' => $row->smw_subobject, |
2144 | 2108 | 'smw_sortkey' => $row->smw_sortkey |
2145 | 2109 | ), |
2146 | | - 'SMW::moveSMWPageID' |
| 2110 | + __METHOD__ |
2147 | 2111 | ); |
2148 | | - |
2149 | 2112 | $targetid = $db->insertId(); |
2150 | 2113 | } else { // change to given id |
2151 | 2114 | $db->insert( 'smw_ids', |
— | — | @@ -2155,11 +2118,15 @@ |
2156 | 2119 | 'smw_subobject' => $row->smw_subobject, |
2157 | 2120 | 'smw_sortkey' => $row->smw_sortkey |
2158 | 2121 | ), |
2159 | | - 'SMW::moveSMWPageID' |
| 2122 | + __METHOD__ |
2160 | 2123 | ); |
2161 | 2124 | } |
2162 | 2125 | |
2163 | 2126 | $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 | + |
2164 | 2131 | $this->changeSMWPageID( $curid, $targetid, $row->smw_namespace, $row->smw_namespace ); |
2165 | 2132 | } |
2166 | 2133 | |
— | — | @@ -2257,7 +2224,7 @@ |
2258 | 2225 | } |
2259 | 2226 | |
2260 | 2227 | // also find subobjects used by this ID ... |
2261 | | - $res = $db->select( 'smw_ids', 'smw_id', |
| 2228 | + $res = $db->select( 'smw_ids', '*', |
2262 | 2229 | 'smw_title = ' . $db->addQuotes( $subject->getDBkey() ) . ' AND ' . |
2263 | 2230 | 'smw_namespace = ' . $db->addQuotes( $subject->getNamespace() ) . ' AND ' . |
2264 | 2231 | 'smw_iw = ' . $db->addQuotes( $subject->getInterwiki() ) . ' AND ' . |
— | — | @@ -2273,6 +2240,8 @@ |
2274 | 2241 | // ... and delete them as well |
2275 | 2242 | foreach ( $res as $row ) { |
2276 | 2243 | $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 |
2277 | 2246 | foreach ( self::getPropertyTables() as $proptable ) { |
2278 | 2247 | if ( $proptable->idsubject ) { |
2279 | 2248 | $db->delete( $proptable->name, array( 's_id' => $row->smw_id ), __METHOD__ ); |
— | — | @@ -2409,25 +2378,24 @@ |
2410 | 2379 | // mark subject as redirect (if it was no redirect before) |
2411 | 2380 | if ( $sid == 0 ) { // every redirect page must have an ID |
2412 | 2381 | $sid = $this->makeSMWPageID( $subject_t, $subject_ns, |
2413 | | - SMW_SQL2_SMWREDIIW, '', false ); |
| 2382 | + SMW_SQL2_SMWREDIIW, '', false ); |
2414 | 2383 | } else { |
2415 | 2384 | $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 ); |
2417 | 2388 | } |
2418 | 2389 | } |
2419 | 2390 | |
2420 | 2391 | $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__ ); |
2424 | 2393 | } else { // delete old redirect |
2425 | 2394 | // This case implies $old_tid != 0 (or we would have new_tid == old_tid above). |
2426 | 2395 | // Therefore $subject had a redirect, and it must also have an ID. |
2427 | 2396 | // This shows that $sid != 0 here. |
2428 | | - $this->m_ids[" $subject_ns $subject_t C"] = $sid; |
2429 | | - |
2430 | 2397 | if ( $smwgQEqualitySupport != SMW_EQ_NONE ) { // mark subject as non-redirect |
2431 | 2398 | $db->update( 'smw_ids', array( 'smw_iw' => '' ), array( 'smw_id' => $sid ), __METHOD__ ); |
| 2399 | + $this->m_idCache->setId( $subject_t, $subject_ns, '', '', $sid ); |
2432 | 2400 | } |
2433 | 2401 | } |
2434 | 2402 | |
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 |
1 | 95 | + native |