This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@mxstbr okay, so I spent a while getting reaaally deep in the rethinkdb docs and found that what we're trying to do is...somewhat complex. There were no clear answers for how to easily implement a
between
call the options we want (author id + descending createdAt timestamp). This is buried in the docs:This is a problem because what we're essentially trying to do is get all posts by an author, but in descending order (indexes are created in ascending order. I still gave it a try by creating a compound index like
author, [r.row('author'), r.row('createdAt')]
, but since you can't get thecreatedAt
to return in descending order it didn't work properly).So I worked around a few possible solutions trying various sorts and filters, but then realized that what we're doing is solving a problem that is only a real problem when we hit massive scale. For now, we can reasonably expect a few thousand story records and querying against those will be nothing for the server.
Given this, I took the following approach:
author
(this is optional)Note: I didn't create an index for story
frequency
but we should be consistent either way we go. If we put an index on bothauthor
andfrequency
it means we can run thegetAll
which might be slightly faster, but honestly given our size it's probably negligible against a standardfilter({ key })
query.paginate
function, which does all the magic of setting thepageInfo
fields.hasNextPage
field properly in the initial queries,fetchMore
queries, and in the story feed component itself.