Skip to content

queryset.sum and queryset.average should use the aggregation framework #569

@wojcikstefan

Description

@wojcikstefan

Using map-reduce is slower, uses both locks (r & w - see http://docs.mongodb.org/manual/faq/concurrency/#which-operations-lock-the-database) and isn't necessary.

@rozza take a look at closeio@50d43c9 and let me know if you like the solution. It works for us and is much faster:

In [4]: %timeit Activity.objects.filter(organization=org).sum('duration')
1 loops, best of 3: 1 s per loop

In [5]: %timeit Activity.objects.filter(organization=org).aggregate_sum('duration')
10 loops, best of 3: 171 ms per loop

In [6]: %timeit Activity.objects.filter(organization=org).sum('duration')
1 loops, best of 3: 989 ms per loop

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions