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

Improve MessageStoreLevel.query() by modifying filters based on the pagination cursor #506

Closed
thehenrytsai opened this issue Sep 18, 2023 · 12 comments
Labels
performance performance improvement refactoring Code refactoring with no functional impact

Comments

@thehenrytsai
Copy link
Contributor

thehenrytsai commented Sep 18, 2023

Background:

At present, even when a pagination cursor is provided, the code executes the same query as if no cursor was supplied, and then trims the resulting array using the cursor.

Task Details:

A potential enhancement could be to adjust the given filters themselves before executing them. This could be done by looking up the value of the corresponding sorted property of message indicated by the cursor. This way, there would be no preceding entries to trim in the resulting array.

@thehenrytsai thehenrytsai added good first issue Good for newcomers refactoring Code refactoring with no functional impact performance performance improvement labels Sep 18, 2023
@EbonyLouis EbonyLouis added the hacktoberfest For the hacking month of October label Sep 26, 2023
@KshitijBharde
Copy link

Hi @thehenrytsai, I would like to pick up this issue.

@jpowell96
Copy link

@KshitijBharde I'd be interested in picking this up too. Would you be open to collaborating on this one?

@jpowell96
Copy link

jpowell96 commented Oct 2, 2023

@thehenrytsai Just a clarifying question about the Pagination object in message-types.ts?

As is, the Pagination type provides a messageCid:

export type Pagination = {
  messageCid?: string
  limit?: number
};

I see that it's used as the start index when you slice the query results in message-store-level.ts.

When you say, "adjust the given filters", would that mean creating a filter based on the messageCid in the Pagination object so that it's considered when querying the index?

Finally, I've also seen different implementations of cursor pagination. In some implementations a user provides a "before" or "after" field that is the cursor you to use for pagination. It often looks something like this:

export type Pagination = {
  beforeMessageCid?: string
  afterMessageCid?: string
  limit?: number
}

With this Pagination type, if I wanted to return the 10 records after afterMessageCid "abc123", my pagination object would look like:

pagination: Pagination = {
  afterMessageCid: "abc123",
  limit: 10
}

This approach can be more complicated though. This is my first time in this repository, so want to clarify the direction you wanted to take.

@EbonyLouis
Copy link
Contributor

@jpowell96 that's a great idea, @KshitijBharde would you be open to collaborating? If you both would like to work on it together we have a hack-together channel in discord I can give you both a stage to work on it.

@KshitijBharde
Copy link

@EbonyLouis @jpowell96 Absolutely! I'm open to collaborating on this one. Let's connect and discuss how we can work together to make it happen.

@thehenrytsai
Copy link
Contributor Author

@jpowell96, really good questions! Shows you definitely understand the task and code at hand!

would that mean creating a filter based on the messageCid in the Pagination object so that it's considered when querying the index?

Yes, you are spot on, right now we "slice" the results AFTER a less efficient query is executed. If we are able to exclude the unnecessary messages with a query, there would be no need to slice the results.

The call out on beforeMessageCid and afterMessageCid is valid, right now it is implied and dependent on "sort order" that the query, I'd imagine a bulk of this PR would have to take into account if the sort order (whether it's descending or ascending). I am open to renames or addition to a mutually exclusive property (beforeMessageCid/afterMessageCid) if everyone thinks if makes everything clearer, though you'll still need to look at the query in the end to look at what property is being sorted.

Adding @LiranCohen in case he has some insights/thoughts/opinions on the potential renames.

@LiranCohen
Copy link
Member

Agreed with @thehenrytsai on the various call outs, as long as it takes into account the higher-level sort property I am open to the before/after naming within the query.

@EbonyLouis
Copy link
Contributor

🥳 @KshitijBharde what's your discord name? if you haven't joined yet here's the link and I can get you both set up.

@KshitijBharde
Copy link

@EbonyLouis here's my discord name: kshitij#3287

@EbonyLouis
Copy link
Contributor

EbonyLouis commented Oct 4, 2023

@KshitijBharde, @jpowell96 you're both set up in discord feel free to message me with any questions my username is EbonyL-TBD

Happy Hacking 🍁

@LiranCohen
Copy link
Member

@KshitijBharde @jpowell96 After speaking with @thehenrytsai today it seems that this isn't a great issue for hacktoberfest after all. It is a little more involved and we are updating some things internally to IndexLevel that would conflict with this work.

Apologies for any spent effort. Hope to see your contributions on some of the other issues!

cc: @EbonyLouis

@LiranCohen LiranCohen removed good first issue Good for newcomers hacktoberfest For the hacking month of October labels Oct 5, 2023
@LiranCohen
Copy link
Member

This was addressed by:
#625

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance performance improvement refactoring Code refactoring with no functional impact
Projects
None yet
Development

No branches or pull requests

5 participants