r23119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23118‎ | r23119 | r23120 >
Date:08:05, 20 June 2007
Author:david
Status:old
Tags:
Comment:
Edit, reply, and start-discussion now work again. Found problem with the deletion optimization when building the thread tree; not sure what it is yet; disabled for now.
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
@@ -4,12 +4,13 @@
55 thread_article int(8) unsigned NOT NULL,
66 thread_path text NOT NULL,
77 thread_summary_page int(8) unsigned NULL,
8 - thread_touched char(14) binary NOT NULL default '',
 8+ thread_timestamp char(14) binary NOT NULL default '',
 9+ thread_revision int(8) unsigned NOT NULL default 1,
910
1011 PRIMARY KEY thread_id (thread_id),
1112 UNIQUE INDEX thread_id (thread_id),
1213 INDEX( thread_path(255) ),
13 - INDEX thread_touched (thread_touched)
 14+ INDEX thread_timestamp (thread_timestamp)
1415 ) TYPE=InnoDB;
1516
1617 /*
Index: branches/liquidthreads/extensions/LqtExtension.php
@@ -232,11 +232,10 @@
233233
234234 // For replies and new posts, insert the associated thread object into the DB.
235235 if ($edit_type != 'editExisting' && $edit_type != 'summarize' && $e->didSave) {
236 - $thread = Thread::newThread( $article, $this->article );
237236 if ( $edit_type == 'reply' ) {
238 - $thread->setSuperthread( $edit_applies_to );
 237+ $thread = Threads::newThread( $article, $this->article, $edit_applies_to );
239238 } else {
240 - $thread->touch();
 239+ $thread = Threads::newThread( $article, $this->article );
241240 }
242241 }
243242
Index: branches/liquidthreads/extensions/LqtModel.php
@@ -100,6 +100,12 @@
101101 }
102102 }
103103
 104+class HistoricalThread {
 105+ static function create( $livethread ) {
 106+ echo ("pretended to create new historical thread.");
 107+ }
 108+}
 109+
104110 class LiveThread {
105111 /* ID references to other objects that are loaded on demand: */
106112 protected $rootId;
@@ -117,9 +123,31 @@
118124 protected $timestamp;
119125 protected $path;
120126
121 - /* Identity */
122127 protected $id;
 128+ protected $revisionNumber;
 129+
 130+ /* Copy of $this made when first loaded from database, to store the data
 131+ we will write to the history if a new revision is commited. */
 132+ protected $double;
 133+
 134+ function commitRevision() {
 135+ // TODO open a transaction.
 136+ HistoricalThread::create( $this->double );
123137
 138+ $this->revisionNumber += 1;
 139+
 140+ $dbr =& wfGetDB( DB_MASTER );
 141+ $res = $dbr->update( 'thread',
 142+ /* SET */array( 'thread_root' => $this->rootId,
 143+ 'thread_article' => $this->articleId,
 144+ 'thread_path' => $this->path,
 145+ 'thread_summary_page' => $this->summaryId,
 146+ 'thread_timestamp' => $this->timestamp,
 147+ 'thread_revision' => $this->revisionNumber ),
 148+ /* WHERE */ array( 'thread_id' => $this->id, ),
 149+ __METHOD__);
 150+ }
 151+
124152 function __construct($line, $children) {
125153 $this->id = $line->thread_id;
126154 $this->rootId = $line->thread_root;
@@ -127,11 +155,13 @@
128156 $this->summaryId = $line->thread_summary_page;
129157 $this->path = $line->thread_path;
130158 $this->timestamp = $line->thread_timestamp;
 159+ $this->revisionNumber = $line->thread_revision;
131160 $this->replies = $children;
 161+ //$this->double = clone $this;
132162 }
133163
134164 function setSuperthread($thread) {
135 - var_dump("warning setSuperthread unimplemented");
 165+ $this->path = $thread->path . '.' . $this->id;
136166 }
137167
138168 function superthread() {
@@ -173,6 +203,10 @@
174204 function id() {
175205 return $this->id;
176206 }
 207+
 208+ function path() {
 209+ return $this->path;
 210+ }
177211
178212 function root() {
179213 if ( !$this->rootId ) return null;
@@ -187,8 +221,8 @@
188222 }
189223
190224 function setSummary( $post ) {
 225+ $this->summary = null;
191226 $this->summaryId = $post->getID();
192 - $this->updateRecord();
193227 }
194228
195229 function wikilink() {
@@ -256,6 +290,31 @@
257291
258292 static $loadedLiveThreads = array();
259293
 294+ static function newThread( $root, $article, $superthread = null ) {
 295+ $dbr =& wfGetDB( DB_MASTER );
 296+ $res = $dbr->insert('thread',
 297+ array('thread_article' => $article->getID(),
 298+ 'thread_root' => $root->getID(),
 299+ 'thread_timestamp' => wfTimestampNow()),
 300+ __METHOD__);
 301+
 302+ $newid = $dbr->insertId();
 303+
 304+ if( $superthread ) {
 305+ $newpath = $superthread->path() . '.' . $newid;
 306+ } else
 307+ {
 308+ $newpath = $newid;
 309+ }
 310+ $res = $dbr->update( 'thread',
 311+ /* SET */ array( 'thread_path' => $newpath ),
 312+ /* WHERE */ array( 'thread_id' => $newid, ),
 313+ __METHOD__);
 314+
 315+ // TODO we could avoid a query here.
 316+ return Threads::withId($newid);
 317+ }
 318+
260319 static function where( $where, $options = array(), $extra_tables = array() ) {
261320 $dbr =& wfGetDB( DB_SLAVE );
262321 if ( is_array($where) ) $where = $dbr->makeList( $where, LIST_AND );
@@ -269,7 +328,11 @@
270329 }
271330
272331 /* Select the client's threads, AND all their children.
273 - The ones the client actually asked for are marked with root_test. */
 332+ The ones the client actually asked for are marked with root_test.
 333+ In theory we could also grab the page and revision data, to avoid having
 334+ to do an additional query for each page, but Article's prodedure for grabbing
 335+ its own data is complicated and it's just not my problem. Plus parser cache.
 336+ */
274337
275338 $root_test = str_replace( 'thread.', 'children.', $where ); // TODO fragile?
276339
@@ -290,7 +353,7 @@
291354
292355 foreach( $lines as $key => $l ) {
293356 if( $l->is_root ) {
294 - unset($lines[$key]);
 357+// unset($lines[$key]);
295358 $threads[] = Threads::buildLiveThread( &$lines, $l );
296359 }
297360 }
@@ -299,11 +362,11 @@
300363
301364 private static function buildLiveThread( $lines, $l ) {
302365 $children = array();
 366+ $l_path = preg_quote($l->thread_path);
303367 foreach( $lines as $key => $m ) {
304 - if ( $m->thread_path != $l->thread_path &&
305 - strpos( $m->thread_path, $l->thread_path ) === 0 ) {
 368+ if ( preg_match( "/^{$l_path}\.\d+$/", $m->thread_path ) ) {
306369 // $m->path begins with $l->path; this is a child.
307 - unset($lines[$key]);
 370+// unset($lines[$key]);
308371 $children[] = Threads::buildLiveThread( &$lines, $m );
309372 }
310373 }

Status & tagging log