dominno / django-moderation

django-moderation is reusable application for Django framework, that allows to moderate any model objects.
BSD 3-Clause "New" or "Revised" License
269 stars 91 forks source link

Default visibilty_column behavior is broken #68

Open manfre opened 12 years ago

manfre commented 12 years ago

From the docs:

If you want a performance boost, define visibility field on your model and add option visibility_column = 'your_field' on moderator class. Field must by a BooleanField. The manager that decides which model objects should be excluded when it were rejected, will first use this option to properly display (or hide) objects that are registered with moderation. Use this option if you can define visibility column in your model and want to boost performance. By default when accessing model objects that are under moderation, one extra query is executed per object in query set to determine if object should be excluded from query set. This method benefit those who do not want to add any fields to their Models. Default: None.

The default behavior of executing an additional query per object is severely broken. It forces the queryset to evaluate immediately, which results in an additional query for every record returned by the parent manager's default queryset. For most models, this is the entire table. This happens regardless of the filter, slicing, and whether or not the queryset is ever meant to be evaluated.

Example:

from django.db import connection

start_query_count = len(connection.queries)
qs = MyModel.objects.all().filter(pk=1)
assert start_query_count == len(connection.queries), 'No queries should have been executed'
arowla commented 12 years ago

I was also interested in getting rid of the query-per-object behavior, as it was causing us severe performance problems, but I just confirmed that adding the visibility_column attribute to the DefaultModerator (or whatever your moderator class is called) indeed fixes the problem. In other words, with visibility_column properly set up, I was not able to reproduce this issue. Using django 1.4 and django-moderation 0.3.2.

mgerring commented 11 years ago

The visibility column option is nice, but the default behavior is still broken.

grucha commented 3 years ago

Hey, is this library still maintained? This issue should have been closed.

DmytroLitvinov commented 3 years ago

Hi @grucha , It is not under active development. If you found any issues, PRs are welcome.