-
Notifications
You must be signed in to change notification settings - Fork 0
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
User Content Feed Loader #34
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.
Nice! This is a clean solution 💯
Sources/MlemMiddleware/Content Models/Person/Person1Providing.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContent.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentFeedLoader.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentFeedLoader.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentFeedLoader.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentFeedLoader.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentFeedLoader.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentFeedLoader.swift
Outdated
Show resolved
Hide resolved
There's also the Modlog |
Co-authored-by: Sjmarf <[email protected]>
…erContentFeedLoader.swift Co-authored-by: Sjmarf <[email protected]>
Modlog is all a single endpoint, but you can specify the specific type to fetch so we can paginate independently--this is the only endpoint that forces you to get everything |
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContent.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentProviding.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/UserContentStream.swift
Outdated
Show resolved
Hide resolved
Sources/MlemMiddleware/FeedLoaders/User Content Feed Loader/PersonContentFeedLoader.swift
Show resolved
Hide resolved
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.
LGTM!
This PR adds a feed loader for user content (mixed posts and comments, used in saved and profile).
For testing, you can use mlemgroup/mlem#1157, which implements the saved feed.
Due to the fact that the API does not provide a type-specific endpoint to load this content, we can't just use the parent/child loader setup; instead, I have implemented a similar architecture but using a much more lightweight "stream" in place of the child loaders. All of this is completely non-generic because as far as I know this is the only case where we have this API constraint, and for all other mixed feeds we can just use the parent/child architecture.
The basic loading concept works like this:
UserContentStream
stores a list of items, their loading thresholds, and their stream cursor. Interaction with them is done through three methods:addItems
: adds new items to the stream. The stream handles updating the loading thresholds.nextItemSortVal
: functions identically to the child feed loader; returns the sort value of the next item in the stream, but does not affect the cursorconsumeNextItem
: returns the next item in the stream and updates the cursorUserContentStream
also provides the convenienceneedsMoreItems
bool, which is true when the stream believes there are more items to load but has reached the end of its items.UserContentFeedLoader
maintains twoUserContentStream
s, one for posts and one for commentsUserContentFeedLoader
performs the same stream merge operation as the parent/child architecture. Unlike a parent tracker, however, at each iteration theUserContentFeedLoader
checks whether either child needs more items and, if so, triggers a load.To support single-type profile feeds,
UserContentFeedLoader
boasts some additional modifications from the standard feed loading architecture:loadIfThreshold
supports checking a particular stream's thresholds. This is not currently used, but is designed to support single-item profile feeds.UserContentFeedLoader
and have lots of thread-unsafe operations. Single-type feeds are therefore exposed through theposts
andcomments
computed vars.This PR also makes a few minor changes:
MiddlewareConstants.infiniteLoadThresholdOffset
is now 10 instead of -10. Arithmetic has been updated accordingly.getContent
now returns a tuple of(posts: [Post2], comments: [Comment2])
instead of aPerson3
, and takes parametersFeedLoaderSortVal.published
has been renamed to.new
. This will let us support.old
in the future.FeedLoader
thresholds are now handled using the newThresholds
struct.