Skip to content

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

Open
wants to merge 1 commit into
base: community-channels
Choose a base branch
from

Conversation

Jakoma02
Copy link
Contributor

Summary

This PR adds bitmask fields for ChannelMetadata categories in kolibri_public and allows filtering the channels by the categories.

Detailed changes:

  • Created separate fields for ContentNode and ChannelMetadata bitmasks in search.py
  • Fixed a bug in the implementation of populating internal data for bitmasks, and moved it to a _populate_bitmask_data method
  • Moved has_all_labels logic under search search.py
  • Created model-specific versions of most bitmask-related methods
  • Added logic for populated the categories bitmask fields to set_channel_metadata_fields
  • Created ChannelMetadataQueryset and ChannelMetadataManager with bitmasks support
  • Refactored bitmasks_contains_and to be a top-level function
  • Added categories and countries to fields returned by ChannelMetadataViewSet (this seems to have been forgotten earlier)
  • Added support for filtering by categories to ChannelMetadataViewSet
  • Moved custom mixer class to a util file and updated it to handle DateTimeTzField and default active database
  • Moved reverse_with_query method to the helpers.py file
  • Added tests for the changes

No 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.

@AlexVelezLl AlexVelezLl self-assigned this Aug 11, 2025
@AlexVelezLl AlexVelezLl linked an issue Aug 13, 2025 that may be closed by this pull request
4 tasks
Copy link
Member

@AlexVelezLl AlexVelezLl left a 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]) :
Copy link
Member

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",
Copy link
Member

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.

Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ESoCC: Add bit_mask fields for kolibri_public ChannelMetadata categories
2 participants