Timeout when displaying a corpus in the Django admin due to millions of SQL queries
Sentry Issue: ARKINDEX-BACKEND-EF
KeyError: 'type'
File "django/db/models/fields/related_descriptors.py", line 173, in __get__
rel_obj = self.field.get_cached_value(instance)
File "django/db/models/fields/mixins.py", line 15, in get_cached_value
return instance._state.fields_cache[cache_name]
SystemExit: 1
(78 additional frame(s) were not displayed)
...
File "django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "django/db/models/sql/compiler.py", line 1156, in execute_sql
cursor.execute(sql, params)
File "contextlib.py", line 239, in helper
return _GeneratorContextManager(func, args, kwds)
File "contextlib.py", line 85, in __init__
doc = getattr(func, "__doc__", None)
File "gunicorn/workers/base.py", line 203, in handle_abort
sys.exit(1)
It seems that a query is made to get the corpus, then the repository, then the element types, then every single element from all corpora, then one query for each element type of each element, resulting in millions of queries.