r58928 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58927‎ | r58928 | r58929 >
Date:20:42, 11 November 2009
Author:kipcool
Status:deferred
Tags:
Comment:
supposedly faster query
Modified paths:
  • /trunk/extensions/Wikidata/OmegaWiki/languages.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Wikidata/OmegaWiki/languages.php
@@ -88,19 +88,39 @@
8989 /* Return SQL query string for fetching language names. */
9090 function getSQLForLanguageNames( $lang_code ) {
9191 /* Use a simpler query if the user's language is English. */
92 - /* Use a simpler query if the user's language is English. */
 92+ /* getLanguageIdForCode( 'en' ) = 85 */
 93+
 94+// alternative query, slower?
 95+// if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) )
 96+// return 'SELECT language.language_id AS row_id,language_names.language_name' .
 97+// ' FROM language' .
 98+// ' JOIN language_names ON language.language_id = language_names.language_id' .
 99+// ' WHERE language_names.name_language_id = 85' ;
 100+// /* Fall back on English in cases where a language name is not present in the
 101+// user's preferred language. */
 102+// else
 103+// return 'SELECT language.language_id AS row_id,COALESCE(ln1.language_name,ln2.language_name) AS language_name' .
 104+// ' FROM language' .
 105+// ' LEFT JOIN language_names AS ln1 ON language.language_id = ln1.language_id AND ln1.name_language_id = ' . $lang_id .
 106+// ' JOIN language_names AS ln2 ON language.language_id = ln2.language_id AND ln2.name_language_id = 85' ;
 107+
93108 if ( $lang_code == 'en' || !( $lang_id = getLanguageIdForCode( $lang_code ) ) )
94109 return 'SELECT language.language_id AS row_id,language_names.language_name' .
95110 ' FROM language' .
96111 ' JOIN language_names ON language.language_id = language_names.language_id' .
97 - ' WHERE language_names.name_language_id = ' . getLanguageIdForCode( 'en' );
 112+ ' WHERE language_names.name_language_id = 85' ;
98113 /* Fall back on English in cases where a language name is not present in the
99114 user's preferred language. */
100115 else
101 - return 'SELECT language.language_id AS row_id,COALESCE(ln1.language_name,ln2.language_name) AS language_name' .
 116+ return 'SELECT language.language_id AS row_id, language_names.language_name AS language_name' .
102117 ' FROM language' .
103 - ' LEFT JOIN language_names AS ln1 ON language.language_id = ln1.language_id AND ln1.name_language_id = ' . $lang_id .
104 - ' JOIN language_names AS ln2 ON language.language_id = ln2.language_id AND ln2.name_language_id = ' . getLanguageIdForCode( 'en' );
 118+ ' JOIN language_names ON language.language_id = language_names.language_id' .
 119+ ' WHERE language_names.name_language_id = ' . $lang_id .
 120+ ' OR ( language_names.name_language_id = 85 ' .
 121+ ' AND language.language_id NOT IN ( SELECT language_id FROM language_names WHERE language_names.name_language_id = ' . $lang_id .
 122+ ' ) ) ' ;
 123+
 124+
105125 }
106126
107127 function getLanguageIdForName( $name ) {

Status & tagging log