OasisLMF / OasisPlatform

Loss modelling platform.
BSD 3-Clause "New" or "Revised" License
40 stars 17 forks source link

Add DB indexing to fields like Analyses status. #1140

Closed sambles closed 6 hours ago

sambles commented 1 week ago

Issue Description

Django supports putting db_index=True on model fields, this can speed up DB level fetch requests:

types-of-database-indexing-in-django https://docs.djangoproject.com/en/5.1/ref/models/indexes/

sambles commented 1 week ago

SubTask Status

https://github.com/OasisLMF/OasisPlatform/blob/8f6e3a650d327556911244815f7fdce542b67a30/src/server/oasisapi/analyses/models.py#L168-L169

analysis.status

https://github.com/OasisLMF/OasisPlatform/blob/8f6e3a650d327556911244815f7fdce542b67a30/src/server/oasisapi/analyses/models.py#L92-L97

sambles commented 1 week ago

Amir: For tables that have group_id in them, I think it also makes sense to have index on group_id, if group_id points to a group of users that belong to a separate security group/organisations. I think group_id index will help finding resources belonging to that group quicker.

Not 100% sure about this but if there is any field that a list query sorts the result based on that, I think indexing on that field might be beneficial. Also any parameter that list endpoints accept as filter parameters could be helpful. But I guess it’s too many index additions it’s better to do it in stages. Because indices consume additional storage in the DB so there might be a considerable storage impact if too many things are indexed.