r4fek / django-cassandra-engine

Django Cassandra Engine - the Cassandra backend for Django
BSD 2-Clause "Simplified" License
365 stars 85 forks source link

Each query seems to execute a count() ? #93

Closed srtonz closed 7 years ago

srtonz commented 7 years ago

I noticed the following behavior when querying a simple model. Any idea why the count query is executed? When running the same query through a plain cassandra.cqlengine.models.Model outside of Django, I don't see the count query

x = list(Data.objects.filter(col5='27'))
[2017-06-21 14:04:41,692] [cassandra.cqlengine.connection] [DEBUG] [Connection: DEFAULT_CONNECTION] SELECT "col1", "col2", "col3", "col4" FROM fx.data WHERE "col5" = %(0)s LIMIT 10000 ALLOW FILTERING (pid: 6998)
[2017-06-21 14:04:42,872] [cassandra.cqlengine.connection] [DEBUG] [Connection: DEFAULT_CONNECTION] SELECT COUNT(*) FROM fx.data WHERE "col5" = %(0)s LIMIT 10000 ALLOW FILTERING (pid: 6998)
srtonz commented 7 years ago

I think this is because the _count attribute is reset here: https://github.com/r4fek/django-cassandra-engine/blob/140e12ce7102204affdafa29faf85edf93d8f021/django_cassandra_engine/models/__init__.py#L675

Not quite sure why that's happening instead of caching the queryset's count() result?

srtonz commented 7 years ago

Any ideas?

r4fek commented 7 years ago

Hey @GeoTob!

Sorry for the delay, I didn't have time to look into it. Could you try with current master now?

srtonz commented 7 years ago

Hey @r4fek This works now, thanks a lot! :+1: