Waldemar Kornewald avatar Waldemar Kornewald committed 828b58d

added support for excluding primary keys in count(). this is not very efficient because it fetches all entities and counts them in memory instead of counting them on the DB

Comments (0)

Files changed (2)

             if path.endswith('google_appengine'):
                 paths.append(path)
         if os.name in ('nt', 'dos'):
-            prefix = '%(PROGRAMFILES)s' % os.environ
-            paths.append(prefix + r'\Google\google_appengine')
+            path = r'%(PROGRAMFILES)s\Google\google_appengine' % os.environ
+            paths.append(path)
         # Loop through all possible paths and look for the SDK dir.
         SDK_PATH = None
         for sdk_path in paths:
     @safe_call
     def fetch(self, low_mark, high_mark):
         query = self._build_query()
+        if self.excluded_pks and high_mark is not None:
+            high_mark += len(self.excluded_pks)
         if self.pk_filters is not None:
             results = self.get_matching_pk(low_mark, high_mark)
         else:
         if self.pk_filters is not None:
             return len(self.get_matching_pk(0, limit))
         if self.excluded_pks:
-            raise DatabaseError("Counting with excluded primary keys is not "
-                                "supported.")
+            return len(list(self.fetch(0, 300)))
         return self._build_query().Count(limit)
 
     @safe_call
         return query
 
     def get_matching_pk(self, low_mark=0, high_mark=None):
-        pk_filters = [key for key in self.pk_filters if key is not None]
-        if not pk_filters:
+        if not self.pk_filters:
             return []
 
-        results = [result for result in Get(pk_filters)
-                   if result is not None
-                       and self.matches_filters(result)]
+        results = [result for result in Get(self.pk_filters)
+                   if result is not None and
+                       self.matches_filters(result)]
         if self.ordering:
             results.sort(cmp=self.order_pk_filtered)
         if high_mark is not None and high_mark < len(results) - 1:
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.