mrjoes/flask-admin — pull request #198 by brAzzi64 (2013-03-26 18:54:41+00:00)
Title: Fix for performance issue when calculating total row count for paging

This is a fix for a performance issue when getting the total row count in the implementation of paging. When dealing with about 250.000 rows, it was taking about 30 secs to show one page on the first load. With this modifications it executes almost instantly.

The problem was that the query applying .count() to the current query generated the SQL:

SELECT count(*) AS count_1
FROM ( SELECT ModelView-columns FROM ModelView-table WHERE conditions ) as anon_1;

which made it actually get all the data in the inner query for then counting the rows and returning the amount. With this modification, the generated query is:

SELECT count(*) AS count_1
FROM ModelView-table
WHERE conditions;

that executes instantly.