Getting total count from datastore

568 views
Skip to first unread message

monmonja

unread,
Nov 2, 2008, 1:58:39 PM11/2/08
to Google App Engine
I created a function and tutorial on how to get the total count from
datastore, the syntax of getting the totalcount count is
get_total_count(self,<your model>)
you can pass any model and it will return you the total count of that
function, you can see the function at
http://monmonja.com/blog/2008/11/get-total-count-from-datastore-in-app-engine/

Now i don't know if this is the best way of doing it but it does not
require you to do some writing on datastore and it uses memcache, if
there is a better way of doing this please stress out. Thanks. :)

David Symonds

unread,
Nov 2, 2008, 11:23:19 PM11/2/08
to google-a...@googlegroups.com
On Sun, Nov 2, 2008 at 11:58 AM, monmonja <almond...@gmail.com> wrote:

> Now i don't know if this is the best way of doing it but it does not
> require you to do some writing on datastore and it uses memcache, if
> there is a better way of doing this please stress out. Thanks. :)

That's a terrible way of doing this: (a) possibly inaccurate, and (b)
unscalable. The correct way to implement such a global counter is via
something like a sharded counter that you increment each time you add
an entity and decrement each time you remove an entity.


Dave.

Dan Sanderson

unread,
Nov 3, 2008, 1:41:28 PM11/3/08
to google-a...@googlegroups.com
See also the docs on fetch(limit, offset):
In particular: "The query has performance characteristics that correspond linearly with the offset amount plus the limit."

-- Dan

monmonja

unread,
Nov 6, 2008, 3:52:52 PM11/6/08
to Google App Engine
Thanks for your input, i already warn people going to the post to use
shared counters. Btw do you have a simple example of it, and what if i
want to count based on a query, say all blog post within july, how can
i count it so that it could scale? Tnx again

On Nov 4, 2:41 am, Dan Sanderson <dansander...@google.com> wrote:
> See also the docs on fetch(limit, offset):http://code.google.com/appengine/docs/datastore/queryclass.html#Query...
>
> In particular: "The query has performance characteristics that correspond
> linearly with the offset amount plus the limit."
>
> -- Dan
>
> On Sun, Nov 2, 2008 at 8:23 PM, David Symonds <dsymo...@gmail.com> wrote:

sebasti...@gmail.com

unread,
Nov 19, 2008, 9:23:32 PM11/19/08
to Google App Engine
what about of using Ajax for dynamic (such as using users parameters)
and complicated counts ? I mean, to leave to JS the responsibility of
summing data that GAE will calculate in bulk of 1000 ? I know.... you
will have the overhead of 1 call for every 1000 records... but at
least you wont risk of getting your process consuming more than the
quota limit of 10 seconds !!! And the user could see some kind of
"nice" progress bar....

On 6 nov, 18:52, monmonja <almondmend...@gmail.com> wrote:
> Thanks for your input, i already warn people going to the post to use
> shared counters. Btw do you have a simple example of it, and what if i
> want tocountbased on a query, say all blog post within july, how can
> icountit so that it could scale? Tnx again
>
> On Nov 4, 2:41 am, Dan Sanderson <dansander...@google.com> wrote:
>
> > See also the docs on fetch(limit, offset):http://code.google.com/appengine/docs/datastore/queryclass.html#Query...
>
> > In particular: "The query has performance characteristics that correspond
> > linearly with the offset amount plus the limit."
>
> > -- Dan
>
> > On Sun, Nov 2, 2008 at 8:23 PM, David Symonds <dsymo...@gmail.com> wrote:
>
> > > On Sun, Nov 2, 2008 at 11:58 AM, monmonja <almondmend...@gmail.com> wrote:
>
> > > > Now i don't know if this is the best way of doing it but it does not
> > > > require you to do some writing ondatastoreand it uses memcache, if
Reply all
Reply to author
Forward
0 new messages