[csw-devel] SF.net SVN: gar:[21719] csw/mgar/gar/v2/lib/python/checkpkg_lib.py

wahwah at users.sourceforge.net wahwah at users.sourceforge.net
Tue Aug 13 01:30:46 CEST 2013


Revision: 21719
          http://gar.svn.sourceforge.net/gar/?rev=21719&view=rev
Author:   wahwah
Date:     2013-08-12 23:30:43 +0000 (Mon, 12 Aug 2013)
Log Message:
-----------
pkgdb: Faster searches for files by basename

Should speed up both the REST interface and the checkpkg invocations.

Modified Paths:
--------------
    csw/mgar/gar/v2/lib/python/checkpkg_lib.py

Modified: csw/mgar/gar/v2/lib/python/checkpkg_lib.py
===================================================================
--- csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2013-08-12 23:28:08 UTC (rev 21718)
+++ csw/mgar/gar/v2/lib/python/checkpkg_lib.py	2013-08-12 23:30:43 UTC (rev 21719)
@@ -969,34 +969,41 @@
     sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad(
         osrel, arch, catrel)
 
-    # Looks like this join is hard to do that way.
-    # res = m.Srv4FileInCatalog.select(
-    #           sqlobject.AND(
-    #               m.Srv4FileInCatalog.q.osrel==sqo_osrel,
-    #               m.Srv4FileInCatalog.q.arch==sqo_arch,
-    #               m.Srv4FileInCatalog.q.catrel==sqo_catrel)).
-    #           throughTo.srv4file.thoughTo.files
+    connection = m.CswFile._connection
+    join = [
+        sqlbuilder.INNERJOINOn(None,
+          m.Pkginst,
+          m.CswFile.q.pkginst==m.Pkginst.q.id),
+        sqlbuilder.INNERJOINOn(None,
+          m.Srv4FileStats,
+          m.CswFile.q.srv4_file==m.Srv4FileStats.q.id),
+        sqlbuilder.INNERJOINOn(None,
+          m.Srv4FileInCatalog,
+          m.Srv4FileStats.q.id==m.Srv4FileInCatalog.q.srv4file),
+    ]
+    where = sqlobject.AND(
+        m.CswFile.q.basename==basename,
+        m.Srv4FileInCatalog.q.osrel==sqo_osrel,
+        m.Srv4FileInCatalog.q.arch==sqo_arch,
+        m.Srv4FileInCatalog.q.catrel==sqo_catrel,
+    )
+    query = connection.sqlrepr(
+        sqlbuilder.Select(
+          [m.CswFile.q.path, m.Pkginst.q.pkgname],
+          where=where,
+          join=join))
+    rows = connection.queryAll(query)
+    pkgs = {}
 
-    # We'll implement it on the application level.  First, we'll get all
-    # the files that match the basename, and then filter them based on
-    # catalog properties.
-    res = m.CswFile.select(m.CswFile.q.basename==basename)
-    file_list = []
-    for f in res:
-      # Check whether osrel, arch and catrel are matching.
-      for cat in f.srv4_file.in_catalogs:
-        if (f.srv4_file.registered
-            and cat.osrel == sqo_osrel
-            and cat.arch == sqo_arch
-            and cat.catrel == sqo_catrel):
-          file_list.append(f)
-    for obj in file_list:
-      pkgs.setdefault(obj.path, [])
-      pkgs[obj.path].append(obj.pkginst.pkgname)
+    for row in rows:
+      file_path, pkginst = row
+      pkgs.setdefault(file_path, []).append(pkginst)
+
     logging.debug("self.error_mgr_mock.GetPathsAndPkgnamesByBasename(%s)"
                   ".AndReturn(%s)", repr(basename), pprint.pformat(pkgs))
     return pkgs
 
+
   def GetPathsAndPkgnamesByBasedir(self, basedir, osrel, arch, catrel):
     sqo_osrel, sqo_arch, sqo_catrel = self.GetSqlobjectTriad(
         osrel, arch, catrel)

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the devel mailing list