[yum-git] yum/sqlitesack.py

James Antill james at linux.duke.edu
Fri May 16 18:32:52 UTC 2008


 yum/sqlitesack.py |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

New commits:
commit b542ece2c1f58d0c9bd3137837ce46fecbc9939b
Author: James Antill <james at and.org>
Date:   Fri May 16 14:32:10 2008 -0400

     Work around SQL limits for searching, still unbearably slow at 1,000s of terms

diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index a4391c3..c9fc26c 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -32,6 +32,8 @@ from sqlutils import executeSQL
 import rpmUtils.miscutils
 import sqlutils
 import constants
+import operator
+import time
 
 def catchSqliteException(func):
     """This decorator converts sqlite exceptions into RepoError"""
@@ -527,6 +529,17 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
         if len(fields) < 1:
             return result
         
+        # NOTE: I can't see any reason not to use this all the time, speed
+        # comparison shows them as baiscally equal.
+        if len(searchstrings) > constants.PATTERNS_MAX:
+            tot = {}
+            for searchstring in searchstrings:
+                matches = self.searchPrimaryFields(fields, searchstring)
+                for po in matches:
+                    tot[po] = tot.get(po, 0) + 1
+            for po in sorted(tot, key=operator.itemgetter, reverse=True):
+                result.append((po, tot[po]))
+            return result
        
         unionstring = "select pkgKey, SUM(cumul) AS total from ( "
         endunionstring = ")GROUP BY pkgKey ORDER BY total DESC"
@@ -536,14 +549,6 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
         #GROUP BY pkgkey ORDER BY total DESC;
         selects = []
         
-        # select pkgKey, 1 AS cumul from packages where description 
-        # like '%devel%' or description like '%python%' or description like '%ssh%'
-#        for f in fields:
-#            basestring = "select pkgKey, 1 AS cumul from packages where %s like '%%%s%%' " % (f,searchstrings[0]) 
-#            for s in searchstrings[1:]:
-#                basestring = "%s or %s like '%%%s%%' " % (basestring, f, s)
-#            selects.append(basestring)
-            
         for s in searchstrings:         
             basestring="select pkgKey,1 AS cumul from packages where %s like '%%%s%%' " % (fields[0], s)
             for f in fields[1:]:
@@ -551,7 +556,6 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             selects.append(basestring)
         
         totalstring = unionstring + " UNION ALL ".join(selects) + endunionstring
-#        print totalstring
         
         for (rep,cache) in self.primarydb.items():
             cur = cache.cursor()



More information about the Yum-cvs-commits mailing list