solid-adventure / trivial-api

Other
1 stars 1 forks source link

enhance/jsonb-keys-retrieval #261

Closed drowninginflowers closed 4 months ago

drowninginflowers commented 4 months ago

Before Querying jsonb columns for distinct keys was resource intensive and failed on large data sets

After

vgkids commented 4 months ago

Currently the search on /apps/:id/activities is not working for apps with a large number of large payloads, because the request to fetch the search keys times out. This is the first of two PRs that will significantly reduce load times of the keys used in activity entry searches.

Step 1 When this is deployed, it will build a materialized view for all activity entry payload keys that exist at that time. We can expect to search to begin working correctly for all existing contracts.

Step 2 A forthcoming PR that triggers an update to the materialized view when new keys are seen. Until then, we can update the view/cache periodically with: POST "/activity_entries/keys?col=payload"

vgkids commented 4 months ago

Note that the migration will take a non-zero amount of time to run.

This 36.5542s is against 660k entries, which have a generally smaller average payload. We don't believe this is locking, so not expecting it to be an issue.

CreateActivityEntryPayloadKeys (20240701191304)
== 20240701191304 CreateActivityEntryPayloadKeys: migrating ===================
-- create_view(:activity_entry_payload_keys, {:materialized=>true})
   -> 36.5542s
-- add_index(:activity_entry_payload_keys, :app_id)
   -> 0.0040s
== 20240701191304 CreateActivityEntryPayloadKeys: migrated (36.5584s) =========