gis4dis / poster_obsolete

Application that accepts POST requests for data collection.
GNU General Public License v3.0
0 stars 0 forks source link

Check indices of ALA tables #23

Open jirik opened 6 years ago

jirik commented 6 years ago

After 1 mil records admin started to be slow

Darkless012 commented 6 years ago

Interesting issue. I've also found this article: https://medium.com/@hakibenita/things-you-must-know-about-django-admin-as-your-app-gets-bigger-6be0b0ee9614

jirik commented 6 years ago

At least part of the problem is related to slow "order by" over multiple columns.

Possible actions

Performance would be probably similar as the previous option.

`CREATE INDEX ala_observation_multi_idx ON ala_observation USING btree (lower(phenomenon_time_range) desc, feature_of_interest_id asc, procedure_id asc, observed_property_id asc, id desc);`
# Django 2.0 only https://docs.djangoproject.com/en/2.0/ref/models/options/#ordering
from django.db.models import Func, F
...
        ordering = [Func(F('phenomenon_time_range'), function='LOWER'), 'feature_of_interest__id', 'procedure__id',
                    'observed_property__id']

Similarly, we can setup duration function:

CREATE OR REPLACE FUNCTION duration(TSTZRANGE) RETURNS INTERVAL AS
$func$
    SELECT UPPER($1) - LOWER($1);
$func$ LANGUAGE SQL STABLE;

And use it also for ordering.

Some sources: