r37617 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37616‎ | r37617 | r37618 >
Date:14:36, 13 July 2008
Author:mkroetzsch
Status:old
Tags:
Comment:
use Job::batchInsert when making many jobs
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/jobs/SMW_UpdateJob.php (modified) (history)
  • /trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_Hooks.php
@@ -124,15 +124,6 @@
125125 }
126126
127127 /**
128 - * Former hook used for storing data. Probably obsolete now (some testing required).
129 - * TODO: delete this when the current architecture has been tested sucessfully
130 - */
131 -function smwfSaveHook(&$article, &$user, &$text) {
132 -// smwfSaveDataForTitle($article->getTitle()); // done by LinksUpdate now
133 - return true;
134 -}
135 -
136 -/**
137128 * Used to updates data after changes of templates, but also at each saving of an article.
138129 */
139130 function smwfLinkUpdateHook($links_update) {
@@ -176,12 +167,13 @@
177168 * updated. To fix this, one would need to store errors as well.
178169 */
179170 function smwfSaveDataForTitle($title) {
 171+ global $smwgEnableUpdateJobs;
180172 $namespace = $title->getNamespace();
181 - $updatejobflag = false;
182173
183174 // Check if the semantic data has been changed.
184175 // Sets the updateflag to true if so.
185 - if ($namespace == SMW_NS_PROPERTY) {
 176+ $updatejobflag = false;
 177+ if ($smwgEnableUpdateJobs && ($namespace == SMW_NS_PROPERTY) ) {
186178 // if it is a property, then we need to check if the type or
187179 // the allowed values have been changed
188180 $oldtype = smwfGetStore()->getSpecialValues($title, SMW_SP_HAS_TYPE);
@@ -194,51 +186,42 @@
195187 $newvalues = SMWFactbox::$semdata->getPropertyValues(SMW_SP_POSSIBLE_VALUE);
196188 $updatejobflag = smwfEqualDatavalues($oldvalues, $newvalues);
197189 }
198 - }
199 -
200 - if ($namespace == SMW_NS_TYPE) {
 190+ } elseif ($smwgEnableUpdateJobs && ($namespace == SMW_NS_TYPE) ) {
201191 // if it is a type we need to check if the conversion factors have been changed
202192 $oldfactors = smwfGetStore()->getSpecialValues($title, SMW_SP_CONVERSION_FACTOR);
203193 $newfactors = SMWFactbox::$semdata->getPropertyValues(SMW_SP_CONVERSION_FACTOR);
204 -
205194 $updatejobflag = smwfEqualDatavalues($oldfactors, $newfactors);
206195 }
207196
208 - // Save semantic data
 197+ // Actually store semantic data
209198 SMWFactbox::storeData(smwfIsSemanticsProcessed($title->getNamespace()));
210199
211200 // Trigger relevant Updatejobs if necessary
212201 if ($updatejobflag) {
 202+ $jobs = array();
213203 $store = smwfGetStore();
214204 if ($namespace == SMW_NS_PROPERTY) {
215205 $subjects = $store->getAllPropertySubjects($title);
216206 foreach ($subjects as $subject) {
217 - smwfGenerateSMWUpdateJobs($subject);
 207+ $jobs[] = new SMWUpdateJob($subject);
218208 }
219209 } elseif ($namespace == SMW_NS_TYPE) {
220210 $dv = SMWDataValueFactory::newSpecialValue(SMW_SP_HAS_TYPE,$title->getDBkey());
221211 $subjects = $store->getSpecialSubjects(SMW_SP_HAS_TYPE, $dv);
222212 foreach ($subjects as $titlesofpropertypagestoupdate) {
223213 $subjectsPropertyPages = $store->getAllPropertySubjects($titlesofpropertypagestoupdate);
224 - smwfGenerateSMWUpdateJobs($titlesofpropertypagestoupdate);
 214+ $jobs[] = new SMWUpdateJob($titlesofpropertypagestoupdate);
225215 foreach ($subjectsPropertyPages as $titleOfPageToUpdate) {
226 - smwfGenerateSMWUpdateJobs($titleOfPageToUpdate);
 216+ $jobs[] = new SMWUpdateJob($titleOfPageToUpdate);
227217 }
228218 }
229219 }
 220+ Job::batchInsert($jobs); ///NOTE: this only happens if $smwgEnableUpdateJobs was true above
230221 }
231222 return true;
232223 }
233224
234225 /**
235 - * Generates a job, which update the semantic data of the responding page
236 - */
237 -function smwfGenerateSMWUpdateJobs(& $title) {
238 - $job = new SMWUpdateJob($title);
239 - $job->insert();
240 -}
241 -
242 -/**
243226 * Restore semantic data if articles are undeleted.
244227 */
245228 function smwfUndeleteHook(&$title, $create) {
Index: trunk/extensions/SemanticMediaWiki/includes/storage/SMW_SQLStore2.php
@@ -1614,7 +1614,7 @@
16151615 * making changes, especially since errors may go unnoticed for some time.
16161616 */
16171617 protected function updateRedirects($subject_t, $subject_ns, $curtarget_t='', $curtarget_ns=-1) {
1618 - global $smwgQEqualitySupport;
 1618+ global $smwgQEqualitySupport, $smwgEnableUpdateJobs;
16191619 $sid = $this->getSMWPageID($subject_t, $subject_ns, '', false); // find real id of subject, if any
16201620 /// NOTE: $sid can be 0 here; this is useful to know since it means that fewer table updates are needed
16211621 $db =& wfGetDB( DB_SLAVE );
@@ -1657,14 +1657,14 @@
16581658 // -> ask SMW to update all affected pages as soon as possible (using jobs)
16591659 //first delete the existing redirect:
16601660 $db->delete('smw_redi2', array('s_title' => $subject_t,'s_namespace' => $subject_ns), 'SMW::updateRedirects');
1661 - if ($smwgQEqualitySupport != SMW_EQ_NONE) { // further updates if equality reasoning is enabled
 1661+ if ( $smwgEnableUpdateJobs && ($smwgQEqualitySupport != SMW_EQ_NONE) ) { // further updates if equality reasoning is enabled
 1662+ $jobs = array();
16621663 $res = $db->select( array('smw_rels2','smw_ids'),'DISTINCT smw_title,smw_namespace',
16631664 's_id=smw_id AND o_id=' . $db->addQuotes($old_tid),
16641665 'SMW::updateRedirects');
16651666 while ($row = $db->fetchObject($res)) {
16661667 $t = Title::makeTitle($row->smw_namespace,$row->smw_title);
1667 - $job = new SMWUpdateJob($t);
1668 - $job->insert();
 1668+ $jobs[] = new SMWUpdateJob($t);
16691669 }
16701670 $db->freeResult($res);
16711671 if ( $subject_ns == SMW_NS_PROPERTY ) {
@@ -1676,8 +1676,7 @@
16771677 'SMW::updateRedirects');
16781678 while ($row = $db->fetchObject($res)) {
16791679 $t = Title::makeTitle($row->smw_namespace,$row->smw_title);
1680 - $job = new SMWUpdateJob($t);
1681 - $job->insert();
 1680+ $jobs[] = new SMWUpdateJob($t);
16821681 }
16831682 }
16841683 $res = $db->select( array('smw_subs2','smw_ids'),'DISTINCT smw_title,smw_namespace',
@@ -1685,8 +1684,7 @@
16861685 'SMW::updateRedirects');
16871686 while ($row = $db->fetchObject($res)) {
16881687 $t = Title::makeTitle($row->smw_namespace,$row->smw_title);
1689 - $job = new SMWUpdateJob($t);
1690 - $job->insert();
 1688+ $jobs[] = new SMWUpdateJob($t);
16911689 }
16921690 } elseif ( $subject_ns == NS_CATEGORY ) {
16931691 foreach (array('smw_subs2','smw_inst2') as $table) {
@@ -1695,11 +1693,11 @@
16961694 'SMW::updateRedirects');
16971695 while ($row = $db->fetchObject($res)) {
16981696 $t = Title::makeTitle($row->smw_namespace,$row->smw_title);
1699 - $job = new SMWUpdateJob($t);
1700 - $job->insert();
 1697+ $jobs[] = new SMWUpdateJob($t);
17011698 }
17021699 }
17031700 }
 1701+ Job::batchInsert($jobs); ///NOTE: this only happens if $smwgEnableUpdateJobs was true above
17041702 }
17051703 }
17061704 // finally, write the new redirect AND refresh your internal canonical id cache!
Index: trunk/extensions/SemanticMediaWiki/includes/jobs/SMW_UpdateJob.php
@@ -65,6 +65,8 @@
6666 /**
6767 * This actually files the job. This is prevented if the configuration of SMW
6868 * disables jobs.
 69+ * NOTE: Any method that inserts jobs with Job::batchInsert or otherwise must
 70+ * implement this check individually. The below is not called in these cases.
6971 */
7072 function insert() {
7173 global $smwgEnableUpdateJobs;

Status & tagging log