Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should not make a query for each row in non-paginated table #427

Closed
jieter opened this issue Feb 27, 2017 · 2 comments · Fixed by mozilla/addons-server#4783 or drummonds/bene#50
Closed

Comments

@jieter
Copy link
Owner

jieter commented Feb 27, 2017

As discussed in #361, this test fails. This seems to be related to #330:

def test_single_query_for_non_paginated_table(settings):
    '''
    A non-paginated table should not generate a query for each row, but only
    one query to count the rows and one to fetch the rows.
    '''
    from django.db import connection
    settings.DEBUG = True

    for i in range(10):
        Person.objects.create(first_name='Bob %d' % i, last_name='Builder')

    num_queries_before = len(connection.queries)

    class PersonTable(tables.Table):
        class Meta:
            model = Person
            fields = ('first_name', 'last_name')
            order_by = ('last_name', 'first_name')

    table = PersonTable(Person.objects.all())

    request = build_request('/')
    RequestConfig(request, paginate=False).configure(table)
    table.as_html(request)
    # or for current master
    # print table.as_values()

    print '\n'.join(q['sql'] for i, q in enumerate(connection.queries) if i > num_queries_before)
    assert len(connection.queries) - num_queries_before == 2

SELECT queries performed:

SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 1
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 2
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 3
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 4
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 5
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 6
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 7
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 8
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 9
SELECT [...] FROM "app_person" ORDER BY "last_name" ASC, "first_name" ASC LIMIT 1 OFFSET 10

(redacted for readability)

@jieter jieter closed this as completed Feb 27, 2017
@jieter jieter reopened this Feb 27, 2017
@jieter
Copy link
Owner Author

jieter commented Feb 27, 2017

bisecting points to 8fe9826, entirely my fault, not #330.

jieter added a commit that referenced this issue Feb 27, 2017
jieter added a commit that referenced this issue Feb 27, 2017
@jieter jieter closed this as completed in 10f5e96 Feb 27, 2017
jieter added a commit that referenced this issue Feb 27, 2017
intiocean pushed a commit to intiocean/django-tables2 that referenced this issue Feb 27, 2017
intiocean pushed a commit to intiocean/django-tables2 that referenced this issue Feb 27, 2017
@jieter
Copy link
Owner Author

jieter commented Feb 27, 2017

released 1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment