r23105 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23104‎ | r23105 | r23106 >
Date:22:27, 19 June 2007
Author:david
Status:old
Tags:
Comment:
Can load additional related threads dynamically with a cache. Moved responsibility for impossible database states into Threads where it belongs.
Modified paths:
  • /branches/liquidthreads/extensions/LqtExtension.php (modified) (history)
  • /branches/liquidthreads/extensions/LqtModel.php (modified) (history)
  • /branches/liquidthreads/maintenance/lqt.sql (modified) (history)

Diff [purge]

Index: branches/liquidthreads/maintenance/lqt.sql
@@ -1,6 +1,6 @@
22 CREATE TABLE /*$wgDBprefix*/thread (
33 thread_id int(8) unsigned NOT NULL auto_increment,
4 - thread_root int(8) unsigned NOT NULL,
 4+ thread_root int(8) unsigned UNIQUE NOT NULL,
55 thread_article int(8) unsigned NOT NULL,
66 thread_path text NOT NULL,
77 thread_summary_page int(8) unsigned NULL,
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -836,10 +836,7 @@
837837 }
838838
839839 function show() {
840 - $ts = Threads::withRoot( $this->article );
841 - if( count($ts) == 0 ) {echo "no such thread"; die();}
842 - if ( count($ts) >1 ) {die();} // TODO handle this screwy situation.
843 - $t = $ts[0];
 840+ $t = Threads::withRoot( $this->article );
844841
845842 // TODO this is a holdover from the special page; not sure what's correct here.
846843 // we now have a real true $this->article that makes some sense.
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -136,13 +136,12 @@
137137 }
138138
139139 function superthread() {
140 - var_dump("warning superthread unimplemented"); return;
141 - // TODO we have to find threads that may not be looked up yet
142 - // and look them up if needed.
143 - if( false === strpos($this->path,'.') ) {
 140+ if( !$this->hasSuperthread() ) {
144141 return null;
145142 } else {
146 - return array_slice( $this->path, strpos($this->path, '.') );
 143+ preg_match("/(\d+)\.\d+$/", $this->path, $matches);
 144+ $superthread_id = $matches[1];
 145+ return Threads::withId( $superthread_id );
147146 }
148147 }
149148
@@ -152,8 +151,13 @@
153152 }
154153
155154 function topmostThread() {
156 - if ( !$this->superthread() ) return $this;
157 - else return $this->superthread()->topmostThread();
 155+ if( !$this->hasSuperthread() ) {
 156+ return $this;
 157+ } else {
 158+ preg_match("/^(\d+)\..*/", $this->path, $matches);
 159+ $superthread_id = $matches[1];
 160+ return Threads::withId( $superthread_id );
 161+ }
158162 }
159163
160164 function setArticle($a) {
@@ -199,7 +203,7 @@
200204 }
201205
202206 function hasDistinctSubject() {
203 - if( $this->superthread() ) {
 207+ if( $this->hasSuperthread() ) {
204208 return $this->superthread()->subjectWithoutIncrement()
205209 != $this->subjectWithoutIncrement();
206210 } else {
@@ -250,6 +254,8 @@
251255
252256 /** Module of factory methods. */
253257 class Threads {
 258+
 259+ static $loadedLiveThreads = array();
254260
255261 static function where( $where, $options = array(), $extra_tables = array() ) {
256262 $dbr =& wfGetDB( DB_SLAVE );
@@ -289,7 +295,6 @@
290296 $threads[] = Threads::buildLiveThread( &$lines, $l );
291297 }
292298 }
293 -
294299 return $threads;
295300 }
296301
@@ -303,31 +308,41 @@
304309 $children[] = Threads::buildLiveThread( &$lines, $m );
305310 }
306311 }
307 - return new LiveThread($l, $children);
 312+ $t = new LiveThread($l, $children);
 313+ Threads::$loadedLiveThreads[$l->thread_id] = $t;
 314+ return $t;
308315 }
309316
 317+ private static function databaseError( $msg ) {
 318+ // TODO tie into MW's error reporting facilities.
 319+ echo("Corrupt liquidthreads database: $msg");
 320+ die();
 321+ }
 322+
310323 static function withRoot( $post ) {
311 - return Threads::where( array('thread.thread_root' => $post->getID()) );
 324+ $ts = Threads::where( array('thread.thread_root' => $post->getID()) );
 325+ if( count($ts) == 0 ) { return null; }
 326+ if ( count($ts) >1 ) {
 327+ Threads::databaseError("More than one thread with thread_root = {$post->getID()}.");
 328+ }
 329+ return $ts[0];
312330 }
313331
314 -}
315 -/*
316 -function lqtCheapTest() {
317 - $threads = Threads::threadsWhere( "thread.thread_id = 1", "order by thread_timestamp" );
318 - function cheapShowThread($t) {
319 - global $wgOut;
320 - $wgOut->addHTML($t->id());
321 - $wgOut->addHTML('<dl><dd>');
322 - foreach( $t->replies as $r ) {
323 - cheapShowThread($r);
 332+ static function withId( $id ) {
 333+ if( array_key_exists( $id, Threads::$loadedLiveThreads ) ) {
 334+ return Threads::$loadedLiveThreads[ $id ];
324335 }
325 - $wgOut->addHTML('</dd></dl>');
 336+
 337+ $ts = Threads::where( array('thread.thread_id' => $id ) );
 338+ if( count($ts) == 0 ) { return null; }
 339+ if ( count($ts) >1 ) {
 340+ Threads::databaseError("More than one thread with thread_id = {$id}.");
 341+ }
 342+ return $ts[0];
326343 }
327 - foreach( $threads as $t ) {
328 - cheapShowThread($t);
329 - }
 344+
330345 }
331 -*/
 346+
332347 class QueryGroup {
333348 protected $queries;
334349

Status & tagging log