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

Refactor: Filters were messy with duplication #58

Closed
wants to merge 3 commits into from
Closed

Conversation

hoh
Copy link
Member

@hoh hoh commented Aug 28, 2023

The management of query filters on API requests was coded inside other functions, hard to read and difficult to read.

Solution: Rely on a MessageQueryFilter object that manages the filters.

A new MessageQuery interface allows an easier handling of pagination, including iterating transparently iterating over messages with async for message in MessageQuery(query_filter=filter).

The interface of AlephClient.get_messages has been kept unchanged for now for compatibility reasons.

Inspired by #54 from @MHHukiewitz

The management of query filters on API requests was coded inside other functions, hard to read and difficult to read.

Solution: Rely on a `MessageQueryFilter` object that manages the filters.

A new `MessageQuery` interface allows an easier handling of pagination, including iterating transparently iterating over messages with `async for message in MessageQuery(query_filter=filter)`.

The interface of `AlephClient.get_messages` has been kept unchanged for now for compatibility reasons.
Copy link
Member

@MHHukiewitz MHHukiewitz left a comment

Choose a reason for hiding this comment

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

Highly appreciated changes! Left a few comments that highlight some issues that might appear with the message iterator.

src/aleph/sdk/query.py Show resolved Hide resolved
http_client_session=self.http_session,
ignore_invalid_messages=ignore_invalid_messages,
invalid_messages_log_level=invalid_messages_log_level,
).fetch(page=page, pagination=pagination)
Copy link
Member

Choose a reason for hiding this comment

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

Seeing this, I wonder if we should ditch the .fetch(page=page, pagination=pagination) call to allow users to decide whether to fetch a certain page or to iterate through all the messages?

Currently I cannot see how a user would actually access the iterator of MessageQuery.

Copy link
Member Author

Choose a reason for hiding this comment

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

The user can always initiate a MessageQuery instance on his own and use it directly. That could even be more elegant, but I am trying to maintain API compatibility.

Copy link
Member

Choose a reason for hiding this comment

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

Regarding this, I cannot help but feel reminded of the way I implemented similar functionality on the Active Record SDK, see: https://github.com/aleph-im/active-record-sdk/blob/main/src/aars/utils.py

Here, we have IndexQuery which prepares the parameters like MessageQueryFilter does.
The AARS client class handles the actual requests, which is here being handled by MessageQuery.
Then PageableRequest & PageableResponse give all the pagination & iteration over the response of the executed MessageQuery.

I got to admit though, that your approach looks more elegant than what I did in the Active Record SDK, but some of this uglyness resulted in the fact that:

  1. I am using an ORM and all the functionality needs to be attached to the base class of Records (which actually represent POSTs).
  2. Some responses are async generators, while some are sync, as AARS does not have a cache capable of async iteration/pagination (while my DomainNode implementation in MessageCache and LightNode #59 does).

I think there is some significant overlap between this PR, the PRs #54 and #59 and the Active Record SDK. Given the right preparation and time for thought, we could build a more coherent and powerful SDK for handling messages as well as POSTs.

One more thing about POSTs: Given the interesting behavior that is possible by amending these messages, I think that they would benefit from the ORM approach chosen in AARS, as it would give users very simple syntax to update/amend POSTs as well as retrieving past revisions of them. This is a paradigm not often seen in DLTs and should be highlighted and easier to work with, IMHO.

@hoh
Copy link
Member Author

hoh commented Oct 23, 2023

@MHHukiewitz is this PR deprecated by #65 ?

@MHHukiewitz
Copy link
Member

MHHukiewitz commented Oct 23, 2023

@hoh yes, it is. I am making an issue out of my last comment, so we can close this

@hoh hoh closed this Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants