Is AssetVersion immutable? – solving performance issues with big forms


I’m trying to resolve performance issues with pretty big forms (~2k questions) with lots of revisions (~100). I have some first little successes that I plan to submit as PRs soon.

What I’m left with is two major pain points that seem inherently complex:

  • in the ReportsViewSet: building the FormPack. With my forms this part of the reports/{uid} query takes ~20s.
  • in the AssetViewSet: getting the content_hash. The whole assets/{uid} request takes ~10s. The trace suggests that over 90% of the time is spent in kpi/models/

The only option for improvement I see here is caching. So, the main question: are AssetVersions immutable?

I’ve skimmed the code and I don’t see them being updated anywhere, but I’d prefer for someone with knowledge of KT to weight in before I start implementing things.

On that note:

  • caching for the content_hash seams easy enough: save the value to a db field on the first request where it’s not cached yet.
  • I’m not sure what’s the best approach for the FormPack. There is a non-trivial amount of logic in there that I guess can change. On top of that it’s not a simple data object, it has classes too. Maybe memcached is a better approach here? With a key that includes the formpack lib git hash? Another option would be two fields in db: cached serialized value + git hash of formpack lib + celery beat job that populates/updates the cache when needed.