? l10n_denormalize_4.patch
? l10n_join.patch
Index: ajax.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/ajax.inc,v
retrieving revision 1.1.2.18.2.4
diff -u -p -r1.1.2.18.2.4 ajax.inc
--- ajax.inc	16 Aug 2009 15:00:51 -0000	1.1.2.18.2.4
+++ ajax.inc	18 Aug 2009 11:07:27 -0000
@@ -23,7 +23,8 @@
  */
 function l10n_community_string_details($langcode = NULL, $sid = 0) {
   // List of project releases, where this string is used.
-  $result = db_query('SELECT p.pid, p.title project_title, r.rid, r.title release_title, COUNT(l.lineno) as occurance_count FROM {l10n_community_project} p INNER JOIN {l10n_community_release} r ON p.pid = r.pid INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid WHERE s.sid = %d AND p.status = 1 GROUP BY r.rid ORDER by p.pid, r.rid', $sid);
+  $result = db_query('SELECT l.pid, p.title project_title, l.rid, r.title release_title, COUNT(l.lineno) as occurance_count FROM {l10n_community_line} l INNER JOIN {l10n_community_project} p ON l.pid = p.pid INNER JOIN {l10n_community_release} r ON l.rid = r.rid WHERE l.sid = %d GROUP BY l.rid ORDER BY l.pid, l.rid', $sid);
+
 
   $list = array();
   $output = array();
Index: export.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/export.inc,v
retrieving revision 1.1.2.15.2.12
diff -u -p -r1.1.2.15.2.12 export.inc
--- export.inc	16 Aug 2009 15:00:51 -0000	1.1.2.15.2.12
+++ export.inc	18 Aug 2009 11:07:27 -0000
@@ -369,19 +369,19 @@ function l10n_community_export($uri, $re
   $project = l10n_community_get_projects(array('uri' => $uri));
   if ($template) {
     // We are exporting a template explicitly.
-    $sql = 'SELECT s.sid, s.value, s.context, f.location, f.revision, l.lineno, l.type FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid WHERE r.pid = %d';
+    $sql = 'SELECT s.sid, s.value, f.location, f.revision, l.lineno, l.type FROM {l10n_community_string} s INNER JOIN {l10n_community_line} l ON s.sid = l.sid INNER JOIN {l10n_community_file} f ON l.fid = f.fid WHERE l.pid = %d';
     $sql_args = array($project->pid);
   }
   else {
     // We only export active translations, not suggestions.
-    $sql = "SELECT s.sid, s.value, s.context, f.location, f.revision, l.lineno, l.type, t.translation, t.uid_approved, t.time_approved FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid  LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND is_active = 1 AND is_suggestion = 0 WHERE r.pid = %d";
+    $sql = "SELECT s.sid, s.value, f.location, f.revision, l.lineno, l.type, t.translation, t.uid_approved, t.time_approved FROM {l10n_community_translation} t LEFT JOIN {l10n_community_string} s ON t.sid = s.sid INNER JOIN {l10n_community_line} l ON s.sid = l.sid INNER JOIN {l10n_community_file} f ON l.fid = f.fid WHERE t.language = '%s' AND is_active = 1 AND is_suggestion = 0 AND l.pid = %d";
     $sql_args = array($language->language, $project->pid);
   }
 
   if (isset($release)) {
     // Release restriction.
     $sql_args[] = $release;
-    $sql .= ' AND r.rid = %d';
+    $sql .= ' AND l.rid = %d';
     $releases = l10n_community_get_releases($uri);
     $release = $releases[$release];
   }
Index: extractor.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/extractor.inc,v
retrieving revision 1.1.2.13.2.4
diff -u -p -r1.1.2.13.2.4 extractor.inc
--- extractor.inc	16 Aug 2009 15:00:51 -0000	1.1.2.13.2.4
+++ extractor.inc	18 Aug 2009 11:07:27 -0000
@@ -146,7 +146,8 @@ function l10n_community_save_file($revis
     }
     else {
       // New file in this release.
-      db_query("INSERT INTO {l10n_community_file} (rid, location, revision) VALUES(%d, '%s', '%s')", $rid, $file, $revision);
+      $pid = db_result(db_query("SELECT pid FROM {l10n_community_release} WHERE rid = %d", $rid));
+      db_query("INSERT INTO {l10n_community_file} (rid, pid, location, revision) VALUES(%d, %d, '%s', '%s')", $rid, $pid, $file, $revision);
       $fid = db_result(db_query("SELECT fid FROM {l10n_community_file} WHERE rid = %d and location = '%s'", $rid, $file));
     }
     $files[$file] = $fid;
@@ -198,12 +199,14 @@ function l10n_community_save_string($val
     }
     if (!db_result(db_query("SELECT fid FROM {l10n_community_line} WHERE fid = %d AND sid = %d AND lineno = %d AND type = %d", $files[$file], $sid, $line, $string_type))) {
       // Location does not exist with this string.
-      db_query("INSERT INTO {l10n_community_line} (fid, sid, lineno, type) VALUES (%d, %d, %d, %d)", $files[$file], $sid, $line, $string_type);
+      $row = db_fetch_object(db_query("SELECT rid, pid FROM {l10n_community_file} WHERE fid = %d", $files[$file]));
+      db_query("INSERT INTO {l10n_community_line} (fid, sid, lineno, type, rid, pid) VALUES (%d, %d, %d, %d, %d, %d)", $files[$file], $sid, $line, $string_type, $row->rid, $row->pid);
+
     }
   }
 }
 
-/**
+/** 
  * Delete the complete contents of a directory recursively.
  *
  * @param $dirname
Index: l10n_community.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.admin.inc,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 l10n_community.admin.inc
--- l10n_community.admin.inc	16 Aug 2009 14:34:44 -0000	1.1.2.7
+++ l10n_community.admin.inc	18 Aug 2009 11:07:28 -0000
@@ -317,15 +317,11 @@ function l10n_community_delete_project($
     $pid
   );
 
-  // Cascade delete all related entries in project, release, file and line.
-  db_query(
-    'DELETE p, r, f, l FROM {l10n_community_project} p
-     INNER JOIN {l10n_community_release} r ON p.pid = r.pid
-     INNER JOIN {l10n_community_file} f ON r.rid = f.rid
-     INNER JOIN {l10n_community_line} l ON f.fid = l.fid
-     WHERE p.pid = %d',
-    $pid
-  );
+  db_query('DELETE l FROM {l10n_community_line} l WHERE l.pid = %d', $pid);
+  db_query('DELETE f FROM {l10n_community_file} f WHERE f.pid = %d', $pid);
+  db_query('DELETE p FROM {l10n_community_project} p WHERE p.pid = %d', $pid);
+  db_query('DELETE r FROM {l10n_community_release} r WHERE r.pid = %d', $pid);
+
 
   if (!$skip_strings) {
     l10n_community_delete_orphans();
Index: l10n_community.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/l10n_community.install,v
retrieving revision 1.1.2.11.2.11
diff -u -p -r1.1.2.11.2.11 l10n_community.install
--- l10n_community.install	16 Aug 2009 15:00:51 -0000	1.1.2.11.2.11
+++ l10n_community.install	18 Aug 2009 11:07:28 -0000
@@ -170,7 +170,13 @@ function l10n_community_schema() {
         'type' => 'int',
         'not null' => FALSE,
         'disp-width' => '11'
-      ),
+        ),
+      'pid' => array(
+        'description' => 'Reference to the {l10n_community_project}.pid of the parent project.',
+        'type' => 'int',
+        'not null' => FALSE,
+        'disp-width' => '11'
+        ),
       'location' => array(
         'description' => 'Path to the file within the release package.',
         'type' => 'varchar',
@@ -199,6 +205,18 @@ function l10n_community_schema() {
         'not null' => FALSE,
         'disp-width' => '11'
       ),
+      'pid' => array(
+        'description' => 'Reference to the {l10n_community_project}.pid of the parent project.',
+        'type' => 'int',
+        'not null' => FALSE,
+        'disp-width' => '11'
+        ),
+      'rid' => array(
+        'description' => 'Reference to the {l10n_community_release}.rid of the parent release.',
+        'type' => 'int',
+        'not null' => FALSE,
+        'disp-width' => '11'
+        ),
       'lineno' => array(
         'description' => 'Number of line where the string occurance was found.',
         'type' => 'int',
@@ -536,3 +554,35 @@ function l10n_community_update_6005() {
   db_add_field($ret, 'l10n_community_string', 'context', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
   return $ret;
 }
+
+/**
+ * Denormalize data in order to improve performance: Push project ID to file table.
+ */
+function l10n_community_update_6006() {
+  $ret = array();
+
+  db_add_field($ret, 'l10n_community_file', 'pid', array('type' => 'int', 'not null' => FALSE, 'disp-width' => 11));
+
+  $q = db_query("SELECT f.fid, r.pid FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid");
+  while ($row = db_fetch_object($q)) {
+    db_query("UPDATE {l10n_community_file} SET pid = %d WHERE fid = %d", $row->pid, $row->fid);
+  }
+  return $ret;
+}
+
+/**
+ * Denormalize data in order to improve performance: Push project and release ID to line table.
+ */
+function l10n_community_update_6007() {
+  $ret = array();
+
+  db_add_field($ret, 'l10n_community_line', 'pid', array('type' => 'int', 'not null' => FALSE, 'disp-width' => 11));
+  db_add_field($ret, 'l10n_community_line', 'rid', array('type' => 'int', 'not null' => FALSE, 'disp-width' => 11));
+
+  $q = db_query("SELECT l.lineno, l.fid, l.sid, l.type, f.rid, f.pid FROM {l10n_community_line} l, {l10n_community_file} f WHERE f.fid = l.fid");
+  while ($row = db_fetch_object($q)) {
+    db_query("UPDATE {l10n_community_line} SET pid = %d, rid = %d WHERE fid = %d AND lineno = %d AND type = %d AND sid = %d", $row->pid, $row->rid, $row->fid, $row->lineno, $row->type, $row->sid);
+  }
+  return $ret;
+}
+
Index: pages.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/pages.inc,v
retrieving revision 1.1.2.20.2.14
diff -u -p -r1.1.2.20.2.14 pages.inc
--- pages.inc	16 Aug 2009 15:00:51 -0000	1.1.2.20.2.14
+++ pages.inc	18 Aug 2009 11:07:28 -0000
@@ -441,7 +441,8 @@ function l10n_community_get_string_count
 
     case 'project':
       // Return a count of all strings in this project, id required.
-      return db_result(db_query('SELECT COUNT(DISTINCT s.sid) FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid WHERE r.pid = %d', $id));
+      return db_result(db_query('SELECT COUNT(DISTINCT s.sid) FROM {l10n_community_string} s INNER JOIN {l10n_community_line} l ON s.sid = l.sid WHERE l.pid = %d', $id));
+
 
     case 'languages':
       // Summeries based on language codes, restricted to a specific project if $id is set.
@@ -452,7 +453,8 @@ function l10n_community_get_string_count
       }
       else {
         // Rather complex join if we also need to factor the project in.
-        $count_sql = "SELECT COUNT(DISTINCT t.sid) AS translation_count, t.language, t.is_suggestion FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid WHERE r.pid = %d AND t.is_active = 1 AND t.translation != '' GROUP BY t.language, t.is_suggestion";
+        $count_sql = "SELECT COUNT(DISTINCT t.sid) AS translation_count, t.language, t.is_suggestion FROM {l10n_community_translation} t INNER JOIN {l10n_community_line} l ON t.sid = l.sid WHERE l.pid = %d AND t.is_active = 1 AND t.translation != '' GROUP BY t.language, t.is_suggestion";
+
       }
       $result = db_query($count_sql, $id);
       while ($row = db_fetch_object($result)) {
@@ -472,19 +474,22 @@ function l10n_community_get_string_count
 
       // First get the count of strings available for translation.
       $sums = $count_args = array();
-      $result = db_query("SELECT COUNT(DISTINCT s.sid) AS string_count, p.pid, p.title, p.uri FROM {l10n_community_project} p INNER JOIN {l10n_community_release} r ON p.pid = r.pid INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid GROUP BY p.pid;");
+      $result = db_query("SELECT COUNT(DISTINCT s.sid) AS string_count, p.pid, p.title, p.uri FROM {l10n_community_string} s INNER JOIN {l10n_community_line} l ON s.sid = l.sid INNER JOIN {l10n_community_project} p ON l.pid = p.pid GROUP BY p.pid");
+
       while ($row = db_fetch_object($result)) {
         // Initialize remaining fields to zeroes too.
         $sums[$row->pid] = array($row->title, $row->uri, $row->string_count, 0, 0);
       }
       // Get the count of distinct strings translated and suggestions per project.
-      $count_sql = "SELECT COUNT(DISTINCT t.sid) AS translation_count, r.pid, t.is_suggestion FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid WHERE t.is_active = 1 AND t.translation != '' ";
+      $count_sql = "SELECT COUNT(DISTINCT t.sid) AS translation_count, l.pid, t.is_suggestion FROM {l10n_community_translation} t LEFT JOIN {l10n_community_string} ON t.sid = s.sid INNER JOIN {l10n_community_line} l ON t.sid = l.sid WHERE t.is_active = 1 AND t.translation != '' ";
+
       if (isset($id)) {
         // Limit to language if desired.
         $count_sql .= "AND t.language = '%s' ";
         $count_args[] = $id;
       }
-      $count_sql .= 'GROUP BY r.pid, t.is_suggestion ';
+      $count_sql .= 'GROUP BY l.pid, t.is_suggestion ';
+
       $result = db_query($count_sql, $count_args);
       while ($row = db_fetch_object($result)) {
         // Fill up the zero spots we added above with real data.
Index: translate.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/l10n_server/l10n_community/Attic/translate.inc,v
retrieving revision 1.1.2.7.2.12
diff -u -p -r1.1.2.7.2.12 translate.inc
--- translate.inc	16 Aug 2009 15:00:51 -0000	1.1.2.7.2.12
+++ translate.inc	18 Aug 2009 11:07:28 -0000
@@ -622,8 +622,8 @@ function l10n_community_get_strings($lan
   }
   else {
     // Project based filtering and language based filtering built in.
-    $sql = "SELECT DISTINCT s.sid, s.value, s.context, t.tid, t.language, t.translation, t.uid_entered, t.uid_approved, t.time_entered, t.time_approved, t.has_suggestion, t.is_suggestion, t.is_active FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE r.pid = %d";
-    $sql_count = "SELECT COUNT(DISTINCT(s.sid)) FROM {l10n_community_release} r INNER JOIN {l10n_community_file} f ON r.rid = f.rid INNER JOIN {l10n_community_line} l ON f.fid = l.fid INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE r.pid = %d";
+    $sql = "SELECT DISTINCT s.sid, s.value, t.tid, t.language, t.translation, t.uid_entered, t.uid_approved, t.time_entered, t.time_approved, t.has_suggestion, t.is_suggestion, t.is_active FROM {l10n_community_line} l INNER JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE l.pid = %d";
+    $sql_count = "SELECT COUNT(DISTINCT(s.sid)) FROM {l10n_community_line} l LEFT JOIN {l10n_community_string} s ON l.sid = s.sid LEFT JOIN {l10n_community_translation} t ON s.sid = t.sid AND t.language = '%s' AND t.is_active = 1 AND t.is_suggestion = 0 WHERE l.pid = %d";
     $sql_args = array($langcode, $project->pid);
   }
 
@@ -640,7 +640,7 @@ function l10n_community_get_strings($lan
     // Release restriction.
     $sql_args[] = $release;
     $sql_args[] = $release;
-    $release_sql = ' AND r.rid = %d';
+    $release_sql = ' AND l.rid = %d';
     $sql .= $release_sql;
     $sql_count .= $release_sql;
   }
