Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -30,7 +30,8 @@ |
31 | 31 | |
32 | 32 | $currentLang = LiveTranslateFunctions::getCurrentLang( $title ); |
33 | 33 | |
34 | | - if ( $title->getFullText() == $egLiveTranslateDirPage ) { |
| 34 | + // FIXME: Hitting the db on every page load should be avoided |
| 35 | + if ( in_array( $title->getFullText(), LiveTranslateFunctions::getLTFMemoryNames() ) ) { |
35 | 36 | LiveTranslateFunctions::createInitialMemoryIfNeeded(); |
36 | 37 | |
37 | 38 | $parser = new LTLTFParser(); |
— | — | @@ -198,7 +199,8 @@ |
199 | 200 | |
200 | 201 | $title = $article->getTitle(); |
201 | 202 | |
202 | | - if ( $title->getFullText() == $egLiveTranslateDirPage ) { |
| 203 | + // FIXME: Hitting the db on every page save should be avoided |
| 204 | + if ( in_array( $title->getFullText(), LiveTranslateFunctions::getLTFMemoryNames() ) ) { |
203 | 205 | $requestData = array( |
204 | 206 | 'action' => 'importtms', |
205 | 207 | 'format' => 'json', |
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php |
— | — | @@ -346,4 +346,31 @@ |
347 | 347 | } |
348 | 348 | } |
349 | 349 | |
| 350 | + /** |
| 351 | + * Returns the pages containing live translate format dictionaries. |
| 352 | + * |
| 353 | + * @since 0.4 |
| 354 | + * |
| 355 | + * @return array |
| 356 | + */ |
| 357 | + public static function getLTFMemoryNames() { |
| 358 | + $dbr = wfGetDb( DB_MASTER ); |
| 359 | + |
| 360 | + $res = $dbr->select( |
| 361 | + 'live_translate_memories', |
| 362 | + array( 'memory_location' ), |
| 363 | + array( 'memory_type' => 0 ), |
| 364 | + __METHOD__, |
| 365 | + array( 'LIMIT' => '5000' ) |
| 366 | + ); |
| 367 | + |
| 368 | + $names = array(); |
| 369 | + |
| 370 | + foreach ( $res as $tm ) { |
| 371 | + $names[] = $tm->memory_location; |
| 372 | + } |
| 373 | + |
| 374 | + return $names; |
| 375 | + } |
| 376 | + |
350 | 377 | } |
\ No newline at end of file |