You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
The text was updated successfully, but these errors were encountered:
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.
From the docs:
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:
The text was updated successfully, but these errors were encountered: