Diego Búrigo Zacarão avatar Diego Búrigo Zacarão committed df7f6bf

Do not delete POFiles when cleaning cache

- The problem was when cleaning and refreshing the component cache.
Due the fact that it deletes all the POFiles from the database
and creates them again, Tx was losing 'locks' and possibly 'watches'
of users, because of the db cascade mechanism.
- This patch allows TX to continue cleaning/refresh the component cache,
however without deleting the POFiles. It sets them as enabled=False
and hide them from the UI.
- Deleting a project or a component thought, still deletes the POFiles
that belong to it, as expected.

Comments (0)

Files changed (2)


         logger.debug("Setting stats for %s." % s.filename)
+        if created:
+            logger.debug("POFile has been created.")
+        else:
+            logger.debug("POFile already existed.")
         if not is_pot:
             lang_code = self.guess_language(filename)
             logger.debug("Guessed language is '%s'." % lang_code)
                 logger.debug("VCS revision for the file has changed.")
+        # If POFile is enabled=False we must enforce the stats calculation
+        if not s.enabled:
+            calcstats, s.enabled = True, True
+            logger.debug("POFile had attr 'enabled=False'.")
         # For intltool components that the pot file has changes, it's
         # necessary to recalc the stats even if the 'rev' is the same
         # FIXME: It's too tied
-        if self.component.i18n_type=='INTLTOOL' and is_msgmerged:
+        elif self.component.i18n_type=='INTLTOOL' and is_msgmerged:
             calcstats = True
+            logger.debug("It's an intltool component with POT changes.")
         if is_pot:
         return self.tm.get_source_file()
     def clean_stats(self):
-        """Clean all stats of translations for the component in the database."""
+        """
+        Set all stats of translations for the component in the database as
+        enabled=False.
+        POFiles with enabled=False do not appear at the UI.
+        """
         logger.debug("Cleaning stats for %s" % self.component)
-        POFile.objects.by_object(self.component).delete()
+        POFile.objects.by_object(self.component).update(enabled=False)
     def clean_old_stats(self):


 class POFileManager(models.Manager):
+    def enabled(self):
+        """Filter POFiles by the 'enabled=True' field."""
+        return self.filter(enabled=True)
     def by_object(self, obj):
         Create a queryset matching all POFiles associated with the given
         ctype = ContentType.objects.get_for_model(obj)
-        return self.filter(content_type__pk=ctype.pk,
+        return self.enabled().filter(content_type__pk=ctype.pk,
     def by_language(self, language):
         """Return a list of objects statistics for a language."""
-        return self.filter(language=language)
+        return self.enabled().filter(language=language)
     def by_release(self, release):
         ctype = ContentType.objects.get(app_label='projects', model='component')
         comp_query = release.components.values('pk').query
-        return self.filter(content_type=ctype, object_id__in=comp_query)
+        return self.enabled().filter(content_type=ctype, object_id__in=comp_query)
     def by_release_and_language(self, release, language):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.