posthog icon indicating copy to clipboard operation
posthog copied to clipboard

fix(query-performance): Speed up permissioning in API

Open macobo opened this issue 3 years ago • 0 comments

Problem

Dashboards load for a long time. Other endpoints suffer from similar overhead.

  • Loading a dashboard with 10 insights was doing upwards of 90 queries total for calculating insight permissions
  • Moving business logic out of models has both performance and maintainability benefits

Changes

  • Consolidate user permissioning logic into a single file instead of spreading it across multiple
    • Adding a test suite for correctness
    • Adding performance shortcuts - avoiding repeated lookups, etc
  • Update all callsites to use new pattern
  • Remove effective_membership_level from team basic serializer as it was not needed and resulted in excessive load

How did you test this code?

  • API tests
  • Note I did not spend too much time adding new N+1 tests beyond ones in user_permissions.py - the main one was 90 queries with the old code.

macobo avatar Jan 04 '23 23:01 macobo