diff --git includes/locale.inc includes/locale.inc
index 578b1b3..e60b8dd 100644
--- includes/locale.inc
+++ includes/locale.inc
@@ -983,7 +983,11 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL
  *   The string ID of the existing string modified or the new string added.
  */
 function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $textgroup, $location, $mode, $plid = 0, $plural = 0) {
-  $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup", array(':source' => $source, ':context' => $context, ':textgroup' => $textgroup))->fetchField();
+  $hashkey = drupal_hash_base64($source . "\0" . $context);
+  $lid = db_query("SELECT lid FROM {locales_source} WHERE hashkey = :hashkey AND textgroup = :textgroup", array(
+    ':hashkey' => $hashkey,
+    ':textgroup' => $textgroup
+  ))->fetchField();
 
   if (!empty($translation)) {
     // Skip this string unless it passes a check for dangerous code.
@@ -1041,6 +1045,7 @@ function _locale_import_one_string_db(&$report, $langcode, $context, $source, $t
           'source' => $source,
           'context' => (string) $context,
           'textgroup' => $textgroup,
+          'hashkey' => $hashkey,
         ))
         ->execute();
 
@@ -1413,7 +1418,8 @@ function _locale_parse_js_file($filepath) {
       // Remove the quotes and string concatenations from the string.
       $string = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($string, 1, -1)));
 
-      $source = db_query("SELECT lid, location FROM {locales_source} WHERE source = :source AND textgroup = 'default'", array(':source' => $string))->fetchObject();
+      $hashkey = drupal_hash_base64($string . "\0");
+      $source = db_query("SELECT lid, location FROM {locales_source} WHERE hashkey = :hashkey AND textgroup = 'default'", array(':hashkey' => $hashkey))->fetchObject();
       if ($source) {
         // We already have this source string and now have to add the location
         // to the location column, if this file is not yet present in there.
@@ -1440,6 +1446,7 @@ function _locale_parse_js_file($filepath) {
             'source' => $string,
             'context' => '',
             'textgroup' => 'default',
+            'hashkey' => $hashkey,
           ))
           ->execute();
       }
diff --git modules/locale/locale.install modules/locale/locale.install
index a144813..82419c7 100644
--- modules/locale/locale.install
+++ modules/locale/locale.install
@@ -204,10 +204,18 @@ function locale_schema() {
         'default' => 'none',
         'description' => 'Version of Drupal, where the string was last used (for locales optimization).',
       ),
+      'hashkey' => array(
+        'description' => 'A sha-256 hash of the concatenation of context and string, used for quick lookups.',
+        'type' => 'char',
+        'length' => 44,
+        'not null' => TRUE,
+        'default' => '',
+      ),
     ),
     'primary key' => array('lid'),
     'indexes' => array(
       'source_context' => array(array('source', 30), 'context'),
+      'hashkey' => array('hashkey'),
     ),
   );
 
diff --git modules/locale/locale.module modules/locale/locale.module
index 9505f72..1c73a4e 100644
--- modules/locale/locale.module
+++ modules/locale/locale.module
@@ -651,10 +651,10 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
   if (!isset($locale_t[$langcode][$context][$string])) {
 
     // We do not have this translation cached, so get it from the DB.
-    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array(
+    $hashkey = drupal_hash_base64($string . "\0" . (string) $context);
+    $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.hashkey = :hashkey AND s.textgroup = 'default'", array(
       ':language' => $langcode,
-      ':source' => $string,
-      ':context' => (string) $context,
+      ':hashkey' => $hashkey,
     ))->fetchObject();
     if ($translation) {
       // We have the source string at least.
@@ -681,6 +681,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) {
           'context' => (string) $context,
           'textgroup' => 'default',
           'version' => VERSION,
+          'hashkey' => $hashkey,
         ))
         ->execute();
       $locale_t[$langcode][$context][$string] = TRUE;
@@ -816,6 +817,12 @@ function locale_system_update($components) {
 function locale_js_alter(&$javascript) {
   global $language;
 
+  if (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update') {
+    // Skip processing for updates because updated code could use updated
+    // database schema probably not compatible with updated processing.
+    return;
+  }
+
   $dir = 'public://' . variable_get('locale_js_directory', 'languages');
   $parsed = variable_get('javascript_parsed', array());
   $files = $new_files = FALSE;
