r87601 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87600‎ | r87601 | r87602 >
Date:23:33, 6 May 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
some preliminary changes to check for changes before updating
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_Store.php
@@ -30,12 +30,12 @@
3131 const STRCOND_PRE = 0;
3232 const STRCOND_POST = 1;
3333 const STRCOND_MID = 2;
34 -
 34+
3535 /**
3636 * String to match.
3737 */
3838 public $string;
39 -
 39+
4040 /**
4141 * Condition. One of STRCOND_PRE (string matches prefix),
4242 * STRCOND_POST (string matches postfix), STRCOND_MID
@@ -62,19 +62,19 @@
6363 * @author Markus Krötzsch
6464 */
6565 class SMWRequestOptions {
66 -
 66+
6767 /**
6868 * The maximum number of results that should be returned.
6969 */
7070 public $limit = -1;
71 -
 71+
7272 /**
7373 * A numerical offset. The first $offset results are skipped.
7474 * Note that this does not imply a defined order of results
7575 * (see SMWRequestOptions->$sort below).
7676 */
7777 public $offset = 0;
78 -
 78+
7979 /**
8080 * Should the result be ordered? The employed order is defined
8181 * by the type of result that are requested: wiki pages and strings
@@ -82,26 +82,26 @@
8383 * numerically. Usually, the order should be fairly "natural".
8484 */
8585 public $sort = false;
86 -
 86+
8787 /**
8888 * If SMWRequestOptions->$sort is true, this parameter defines whether
8989 * the results are ordered in ascending or descending order.
9090 */
9191 public $ascending = true;
92 -
 92+
9393 /**
9494 * Specifies a lower or upper bound for the values returned by the query.
9595 * Whether it is lower or upper is specified by the parameter "ascending"
9696 * (true->lower, false->upper).
9797 */
9898 public $boundary = null;
99 -
 99+
100100 /**
101101 * Specifies whether or not the requested boundary should be returned
102102 * as a result.
103103 */
104104 public $include_boundary = true;
105 -
 105+
106106 /**
107107 * An array of string conditions that are applied if the result has a
108108 * string label that can be subject to those patterns.
@@ -124,7 +124,7 @@
125125 public function getStringConditions() {
126126 return $this->stringcond;
127127 }
128 -
 128+
129129 }
130130
131131
@@ -253,8 +253,8 @@
254254 * includes relations, attributes, and special properties. This does
255255 * not delete the respective text from the wiki, but only clears the
256256 * stored data.
257 - *
258 - * @param Title $subject
 257+ *
 258+ * @param Title $subject
259259 */
260260 public abstract function deleteSubject( Title $subject );
261261
@@ -262,8 +262,8 @@
263263 * Update the semantic data stored for some individual. The data is
264264 * given as a SMWSemanticData object, which contains all semantic data
265265 * for one particular subject.
266 - *
267 - * @param SMWSemanticData $data
 266+ *
 267+ * @param SMWSemanticData $data
268268 */
269269 public abstract function doDataUpdate( SMWSemanticData $data );
270270
@@ -277,27 +277,46 @@
278278 public function updateData( SMWSemanticData $data ) {
279279 wfRunHooks( 'SMWStore::updateDataBefore', array( $this, $data ) );
280280
281 - $this->doDataUpdate( $data );
 281+ global $smwgCheckChangesBeforeUpdate;
 282+ if ( $smwgCheckChangesBeforeUpdate && $data->hasVisibleProperties() ) {
 283+ $this->removeNotChangedProperties( $data );
 284+ }
282285
283 - // Invalidate the page, so data stored on it gets displayed immediately in queries.
284 - global $smwgAutoRefreshSubject;
285 - if ( $smwgAutoRefreshSubject && !wfReadOnly() ) {
286 - $title = Title::makeTitle( $data->getSubject()->getNamespace(), $data->getSubject()->getDBkey() );
287 - $dbw = wfGetDB( DB_MASTER );
 286+ if ( true /* TODO: something changed */ ) {
 287+ // Invalidate the page, so data stored on it gets displayed immediately in queries.
 288+ global $smwgAutoRefreshSubject;
 289+ if ( $smwgAutoRefreshSubject && !wfReadOnly() ) {
 290+ $title = Title::makeTitle( $data->getSubject()->getNamespace(), $data->getSubject()->getDBkey() );
 291+ $dbw = wfGetDB( DB_MASTER );
288292
289 - $dbw->update(
290 - 'page',
291 - array( 'page_touched' => $dbw->timestamp( time() + 9001 ) ),
292 - $title->pageCond(),
293 - __METHOD__
294 - );
 293+ $dbw->update(
 294+ 'page',
 295+ array( 'page_touched' => $dbw->timestamp( time() + 9001 ) ),
 296+ $title->pageCond(),
 297+ __METHOD__
 298+ );
295299
296 - HTMLFileCache::clearFileCache( $title );
297 - }
 300+ HTMLFileCache::clearFileCache( $title );
 301+ }
 302+ }
298303
 304+ $this->doDataUpdate( $data );
 305+
299306 wfRunHooks( 'SMWStore::updateDataAfter', array( $this, $data ) );
300307 }
301 -
 308+
 309+ protected function removeNotChangedProperties( SMWSemanticData &$data ) {
 310+ $storedValues = $this->getStoredValues( $data );
 311+
 312+ // TODO: remove data that has not changed
 313+
 314+ if ( false /* TODO: something changed */ ) {
 315+ wfRunHooks( 'SMWStore::dataChanged', array( $this, $data ) );
 316+ }
 317+ }
 318+
 319+ protected abstract function getStoredValues( SMWSemanticData $data );
 320+
302321 /**
303322 * Clear all semantic data specified for some page.
304323 *
@@ -328,8 +347,8 @@
329348 * MODE_COUNT or MODE_DEBUG) a plain wiki and HTML-compatible string is
330349 * returned.
331350 *
332 - * @param SMWQuery $query
333 - *
 351+ * @param SMWQuery $query
 352+ *
334353 * @return SMWQueryResult
335354 */
336355 public abstract function getQueryResult( SMWQuery $query );

Status & tagging log