-
Notifications
You must be signed in to change notification settings - Fork 215
Add bitmask fields for ChannelMetadata categories #5272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: community-channels
Are you sure you want to change the base?
Add bitmask fields for ChannelMetadata categories #5272
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Jakoma02! The bitmasks annotation, and the categories filter are working as expected! And thanks for fixing the bug in the bitmask_lookup computation! I just noted one little bug with the countries
field in the values
list, but we can fix this in a follow up if it makes more sense!
for key, labels in metadata_lookup.items(): | ||
bitmask_lookup = {} | ||
i = 0 | ||
while (chunk := labels[i : i + 64]) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -133,6 +142,8 @@ class ChannelMetadataViewSet(ReadOnlyValuesViewset): | |||
"public", | |||
"total_resource_count", | |||
"published_size", | |||
"categories", | |||
"countries", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a small problem with having the countries
value here, this makes the channels query to join the country table, and if we have a channel with multiple countries, the query will return duplicated records for each channel. We sometimes solve this by grouping the entity instances and group the multi-value field into an array (e.g. here).
But this method isn't that elegant, and if we filter by that field (in this case, the countries), this countries
array will just contain the filtered values, not the actual set of countries of that channel. So thats why we sometimes prefer to query these multi-value fields separately and annotate them in the consolidate
method (it can also be in the annotate
method), just like we did to set the countries in the Community Library Submission viewset here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, now that we are returning the countries here. Could you also add a countries
filter here, please? It should be a CharInFilter that filters by the country code. I know this issue wasn't originally intended for this 😅, but now that we are here, it'd be nice if we include it too, it should be just a couple of lines. We can also do it in a follow up if that makes more sense!
Summary
This PR adds bitmask fields for ChannelMetadata categories in
kolibri_public
and allows filtering the channels by the categories.Detailed changes:
ContentNode
andChannelMetadata
bitmasks insearch.py
_populate_bitmask_data
methodhas_all_labels
logic under searchsearch.py
set_channel_metadata_fields
ChannelMetadataQueryset
andChannelMetadataManager
with bitmasks supportbitmasks_contains_and
to be a top-level functioncategories
andcountries
to fields returned byChannelMetadataViewSet
(this seems to have been forgotten earlier)ChannelMetadataViewSet
DateTimeTzField
and default active databasereverse_with_query
method to thehelpers.py
fileNo manual testing apart from running automated tests was done.
References
Resolves #5208.
A WIP branch with an alternative implementation using a mixin (ended up not being pursued) can be found at https://github.com/Jakoma02/studio/tree/wip-channel-categories-bit-masks-mixin.
Reviewer guidance
Nothing.