You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR denormalises the feature names directly into an ArrayField on the FeatureFlagCodeReferencesScan. The feature names were previously nested inside the JSONField which caused performance issues with the database queries when listing features for the dashboard.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.34%. Comparing base (800ac8d) to head (2b03644). ⚠️ Report is 4 commits behind head on main.
The PR migrates the last_feature_found_at subquery and the get_code_references_for_feature_flag function to use the new feature_names array, but the count calculation in
counts_by_repository (the heavier operation) still does a full jsonb_path_query_array + jsonb_array_length against the raw code_references JSON blob:
count=Func(
Func(
F("code_references"),
Value("$[*] ? (@.feature_name == $feature_name)"),
JSONObject(feature_name=F("feature_name")),
function="jsonb_path_query_array",
),
function="jsonb_array_length",
),
This generates SQL like:
jsonb_array_length(
jsonb_path_query_array(
V0."code_references",
'$[*] ? (@.feature_name == $feature_name)',
JSONB_BUILD_OBJECT('feature_name', "features_feature"."name")
)
)
The only solution I see here is to accept that the data model doesn't work for how we query it, and change it to flatten everything and get rid of the JSON column. Otherwise, we'd keep going in circles making the data access layer more complicated than it needs to be.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Closes #6836
This PR denormalises the feature names directly into an ArrayField on the
FeatureFlagCodeReferencesScan. The feature names were previously nested inside the JSONField which caused performance issues with the database queries when listing features for the dashboard.How did you test this code?
Added tests.