diff options
author | Chris Moyer <kopertop@MacPro.local> | 2010-08-19 13:29:56 -0400 |
---|---|---|
committer | Chris Moyer <kopertop@MacPro.local> | 2010-08-19 13:29:56 -0400 |
commit | 9731c220f2611db6aec645a0e322b0317663a1f2 (patch) | |
tree | e0b4bb0140d292de748515c949d4d3e2f6095175 | |
parent | 7bb3a030da0b45d5197d6a9c2a3025aa8deb10b5 (diff) | |
download | boto-9731c220f2611db6aec645a0e322b0317663a1f2.tar.gz |
Updated SDBManager and query to take an optional "quick" parameter
which now specifies if we should do a full count, or just return the
first result set. This is due to Amazon's definition of count(*):
If the count request takes more than five seconds, Amazon SimpleDB
returns the number of items that it could count and a next token to
return additional results. The client is responsible for accumulating
the partial counts.
But in the general case, we don't want to take a long time returning the
count, we just want a quick result. Quick is set to "True" by default,
but you can get a FULL count by doing:
query.count(False)
-rw-r--r-- | boto/sdb/db/manager/sdbmanager.py | 8 | ||||
-rw-r--r-- | boto/sdb/db/query.py | 4 |
2 files changed, 8 insertions, 4 deletions
diff --git a/boto/sdb/db/manager/sdbmanager.py b/boto/sdb/db/manager/sdbmanager.py index 371c14aa..7221dfe2 100644 --- a/boto/sdb/db/manager/sdbmanager.py +++ b/boto/sdb/db/manager/sdbmanager.py @@ -445,13 +445,17 @@ class SDBManager(object): query.rs = rs return self._object_lister(query.model_class, rs) - def count(self, cls, filters): + def count(self, cls, filters, quick=True): """ Get the number of results that would be returned in this query """ query = "select count(*) from `%s` %s" % (self.domain.name, self._build_filter_part(cls, filters)) - count = int(self.domain.select(query).next()["Count"]) + count = 0 + for row in self.domain.select(query): + count += int(row['Count']) + if quick: + return count return count diff --git a/boto/sdb/db/query.py b/boto/sdb/db/query.py index 2660a42d..dfbe593d 100644 --- a/boto/sdb/db/query.py +++ b/boto/sdb/db/query.py @@ -53,8 +53,8 @@ class Query(object): self.offset = offset return self - def count(self): - return self.manager.count(self.model_class, self.filters) + def count(self, quick=True): + return self.manager.count(self.model_class, self.filters, quick) def get_query(self): return self.manager._build_filter_part(self.model_class, self.filters, self.sort_by) |