Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -888,9 +888,13 @@ |
889 | 889 | } else { |
890 | 890 | $thread->initWithReplies( array() ); |
891 | 891 | } |
| 892 | + |
| 893 | + self::$cache_by_root[$thread->root()->getID()] = $thread; |
892 | 894 | } |
893 | 895 | return $top_level_threads; |
894 | 896 | } |
| 897 | + |
| 898 | + static $cache_by_root = array(); |
895 | 899 | |
896 | 900 | private static function databaseError( $msg ) { |
897 | 901 | // TODO tie into MW's error reporting facilities. |
— | — | @@ -899,6 +903,15 @@ |
900 | 904 | } |
901 | 905 | |
902 | 906 | static function withRoot( $post ) { |
| 907 | + if( $post->getTitle()->getNamespace() != NS_LQT_THREAD ) { |
| 908 | + // No articles outside the thread namespace have threads associated with them; |
| 909 | + // avoiding the query saves time during the TitleGetRestrictions hook. |
| 910 | + return null; |
| 911 | + } |
| 912 | + if( array_key_exists( $post->getID(), self::$cache_by_root ) ) { |
| 913 | + return self::$cache_by_root[$post->getID()]; |
| 914 | + } |
| 915 | + efVarDump(null, "withRoot( {$post->getID()} ) missed."); |
903 | 916 | $ts = Threads::where( array('thread.thread_root' => $post->getID()) ); |
904 | 917 | if( count($ts) == 0 ) { return null; } |
905 | 918 | if ( count($ts) >1 ) { |