Skip to content

Commit

Permalink
remove channel metedata for internal api
Browse files Browse the repository at this point in the history
  • Loading branch information
ozer550 committed Jan 8, 2025
1 parent d0d359c commit be9d1f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
13 changes: 7 additions & 6 deletions kolibri/core/content/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ class OptionalPagination(ValuesViewsetCursorPagination):

class OptionalContentNodePagination(OptionalPagination):
use_deprecated_channels_labels = False
ordering = ("lft", "id")

def paginate_queryset(self, queryset, request, view=None):
# Record the queryset for use in returning available filters
Expand All @@ -836,17 +837,17 @@ def paginate_queryset(self, queryset, request, view=None):
)

def get_paginated_response(self, data):
labels = (
get_available_metadata_labels(self.queryset)
if self.use_deprecated_channels_labels
else {}
)
return Response(
OrderedDict(
[
("more", self.get_more()),
("results", data),
("labels", labels),
(
"labels",
get_available_metadata_labels(
self.queryset, self.use_deprecated_channels_labels
),
),
]
)
)
Expand Down
17 changes: 17 additions & 0 deletions kolibri/core/content/test/test_content_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,23 @@ def test_contentnode_list(self):
self.assertEqual(len(response.data), expected_output)
self._assert_nodes(response.data, nodes)

def test_contentnode_channel_metadata_label_absent_in_internal_api(self):
response = self._get(
reverse("kolibri:core:contentnode-list"), data={"max_results": 5}
)
self.assertEqual(response.status_code, 200)
if not self.baseurl:
self.assertNotIn("channels", response.data.get("labels"))
else:
self.assertIn("channels", response.data.get("labels"))

def test_contentnode_channel_metadata_label_present_in_public_api(self):
response = self._get(
reverse("kolibri:core:publiccontentnode-list"), data={"max_results": 5}
)
self.assertEqual(response.status_code, 200)
self.assertIn("channels", response.data.get("labels"))

def test_contentnode_etag(self):
root = content.ContentNode.objects.get(title="root")
nodes = root.get_descendants(include_self=True).filter(available=True)
Expand Down
10 changes: 7 additions & 3 deletions kolibri/core/content/utils/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ def template(self):
)


def get_available_metadata_labels(base_queryset): # noqa: C901
def get_available_metadata_labels( # noqa: C901
base_queryset, use_deprecated_channels_labels
):
from kolibri.core.device.models import ContentCacheKey

content_cache_key = ContentCacheKey.get_cache_key()
try:
cache_key = "search-labels:{}:{}".format(
cache_key = "search-labels:{}:{}:{}".format(
content_cache_key,
hashlib.md5(str(base_queryset.query).encode("utf8")).hexdigest(),
"with-channels" if use_deprecated_channels_labels else "no-channels",
)
except EmptyResultSet:
return empty_labels
Expand All @@ -137,7 +140,8 @@ def get_available_metadata_labels(base_queryset): # noqa: C901
if bit_value is not None and bit_value & value["bits"]:
output[value["field_name"]].append(value["label"])
output["languages"] = _get_available_languages(base_queryset)
output["channels"] = _get_available_channels(base_queryset)
if use_deprecated_channels_labels:
output["channels"] = _get_available_channels(base_queryset)
cache.set(cache_key, output, timeout=None)
return cache.get(cache_key)

Expand Down

0 comments on commit be9d1f5

Please sign in to comment.