Skip to content
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

[PP-1509] Add support for default facet #2142

Merged
merged 11 commits into from
Nov 5, 2024

Conversation

dbernstein
Copy link
Contributor

@dbernstein dbernstein commented Oct 28, 2024

Description

With this update, the "default" facet or sort link will have a http://palaceproject.io/terms/properties/default property to indicate that it is a default property. This default property will be present in both OPDS1 and OPDS2 feeds. However in order to see them, clients must specify an api-version of 2 in the mimetype.

For OPDS 1:
application/atom+xml;api-version=2
For OPDS 2:
application/opds+json;api-version=2

Otherwise version 1 of both formats will be delivered. Version 1 is what is currently deployed in production.

Here is an update to the documentation that covers these updates.

I do have an open question about whether or not a default facet that happens to be active should have an "activeFacet" or "active-sort" set to true.

Motivation and Context

https://ebce-lyrasis.atlassian.net/browse/PP-1506

How Has This Been Tested?

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@dbernstein dbernstein marked this pull request as draft October 28, 2024 22:25
Copy link

codecov bot commented Oct 29, 2024

Codecov Report

Attention: Patch coverage is 93.38235% with 9 lines in your changes missing coverage. Please review.

Project coverage is 90.78%. Comparing base (7411b60) to head (dfa6472).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/palace/manager/feed/serializer/opds.py 89.47% 2 Missing and 4 partials ⚠️
src/palace/manager/feed/serializer/opds2.py 94.91% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2142   +/-   ##
=======================================
  Coverage   90.78%   90.78%           
=======================================
  Files         350      350           
  Lines       40608    40691   +83     
  Branches     8796     8822   +26     
=======================================
+ Hits        36864    36940   +76     
- Misses       2439     2441    +2     
- Partials     1305     1310    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbernstein dbernstein marked this pull request as ready for review October 29, 2024 21:18
@dbernstein dbernstein force-pushed the PP-1509-add-support-for-default-facet branch from 292d66b to 8ff807c Compare October 29, 2024 21:18
@dbernstein dbernstein requested a review from a team October 29, 2024 21:20
@jonathangreen jonathangreen self-assigned this Oct 30, 2024
@jonathangreen jonathangreen added the feature New feature label Oct 30, 2024
Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few comments to look at before this one goes in.

Can you also update the PR with a small example of what these links look like in the different feed versions?

src/palace/manager/feed/serializer/opds.py Outdated Show resolved Hide resolved
src/palace/manager/feed/serializer/opds.py Outdated Show resolved Hide resolved
src/palace/manager/feed/serializer/opds.py Outdated Show resolved Hide resolved
# TODO: When we remove the facet-based sort links [PP-1814],
# this code path will be removed and we'll want to pull the sort
# link data from the feed.sort_links once that is in place.
link_data["links"].append(self._serialize_sort_link(link))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this TODO get relocated rather then removed?

src/palace/manager/feed/opds.py Outdated Show resolved Hide resolved
src/palace/manager/feed/serializer/opds.py Outdated Show resolved Hide resolved
src/palace/manager/feed/serializer/opds2.py Outdated Show resolved Hide resolved
tests/manager/feed/test_opds_base.py Outdated Show resolved Hide resolved
tests/manager/feed/test_opds_base.py Outdated Show resolved Hide resolved
serialized.append(link)

for link in self._serialize_sort_links(feed.facet_links):
serialized.append(link)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it would be good to have a test that covers this line, to make sure we are getting the expected sort links in the OPDS1Version2 feed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still doesn't look like there is any coverage here?

@jonathangreen jonathangreen removed their assignment Oct 30, 2024
@dbernstein
Copy link
Contributor Author

@jonathangreen : thanks for the review. All your suggests look reasonable to me. I'll update the PR today.

@dbernstein dbernstein force-pushed the PP-1509-add-support-for-default-facet branch 5 times, most recently from e03180c to a23686b Compare November 4, 2024 16:39
Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple more comments here that would be nice to get resolved before merging @dbernstein.

class OPDS1Serializer(SerializerInterface[etree._Element], OPDSFeed):
"""An OPDS 1.2 Atom feed serializer"""

class BaseOPDS1Serializer(SerializerInterface[etree._Element], OPDSFeed):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to inherent from ABC in order to make this an abstract base class.

See:
https://docs.python.org/3/library/abc.html#abc.ABC

@@ -79,7 +84,7 @@ def _tag(

def _attr_name(self, attr_name: str, mapping: dict[str, str] | None = None) -> str:
if not mapping:
mapping = ATTRIBUTE_MAPPING
mapping = V1_ATTRIBUTE_MAPPING
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we defined _get_attribute_mapping, shouldn't this be calling that function?

serialized.append(link)

for link in self._serialize_sort_links(feed.facet_links):
serialized.append(link)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still doesn't look like there is any coverage here?

value if value is not None else "",
)
return entry

@abc.abstractmethod
def _get_attribute_mapping(self) -> dict[str, str]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.

@@ -405,13 +413,95 @@ def _serialize_data_entry(self, entry: DataEntry) -> etree._Element:
def to_string(cls, element: etree._Element) -> str:
return cast(str, etree.tostring(element, encoding="unicode"))

@abc.abstractmethod
def content_type(self) -> str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.

pass

@abc.abstractmethod
def _serialize_facet_links(self, feed: FeedData) -> list[Link]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.

pass

@abc.abstractmethod
def _serialize_sort_links(self, feed: FeedData) -> list[Link]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Since subclasses are expected to implement these, its would be nice to have a doc comment with a small bit of explanation of what an implementation should provide for this function.

# select only the sort facets for serialization
if is_sort_facet(link):
links.append(self._serialize_sort_link(link))
return links

def _serialize_sort_link(self, link: Link) -> etree._Element:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We aren't using the @override decorator anywhere else in the codebase currently. I think if we're going to apply it in these classes we should apply it consistently, so it should get added to this method as well.

],
)
def test_get_serializer1(self, accept_header: str, serializer):
# The q-value should take priority
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Seems like this comment is outdated.

Comment on lines 134 to 137
(
OPDS2Serializer.CONTENT_TYPE,
OPDS2Serializer.CONTENT_TYPE,
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(
OPDS2Serializer.CONTENT_TYPE,
OPDS2Serializer.CONTENT_TYPE,
),
(OPDS2Serializer.CONTENT_TYPE, OPDS2Serializer.CONTENT_TYPE),

Minor: This change seems unnecessary. Its nice to have these be consistent, instead of having this one entry on multiple lines.

@dbernstein dbernstein force-pushed the PP-1509-add-support-for-default-facet branch from 2bce84e to dfa6472 Compare November 5, 2024 19:45
@dbernstein dbernstein merged commit c4ebcb7 into main Nov 5, 2024
21 checks passed
@dbernstein dbernstein deleted the PP-1509-add-support-for-default-facet branch November 5, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants