I am able to query events from specific model instances by using the following query: /experimental/events/model/{modelStreamId}.
The issue is that the response is ordered lexicographically by event ID, not by creation time.
This makes it tricky to fetch only the most recent events — resumeOffset isn’t helpful when the last event in the response isn’t actually the latest chronologically.
You can see this in the following image, where I had 20 events and then generated a new one summing up 21, and this latest one was added in the middle of the response:
Hi @Eloy, can you use the feed API and see? That one is meant to deliver events in a predictable order. You can also use FlightSQL to filter out events for the model you’re interested in.
For example, this is the CLI method of filtering out event states by the Model ID kjzl6hvfrbw6cbe01it6hlcwopsv4cqrqysho4f1xd7rtqxew9yag3x2wxczhz0:
ceramic-one query statement-query "SELECT DISTINCT ON (stream_cid)
event_state_order
from event_states
where stream_id_string(arrow_cast(dimension_extract(dimensions, 'model'),'Binary')) = 'kjzl6hvfrbw6cbe01it6hlcwopsv4cqrqysho4f1xd7rtqxew9yag3x2wxczhz0'
ORDER BY event_state_order;"
The event_state_order is a global order and should give you events in the order you’re expecting.
You can find some examples of how to use the SDK for this in our tests.
But @mohsin using feed api will return a resume token number and ids that are probably ordered lexicographically too, right?
Anyways, I thought about using feed but the problem is that it returns all the events related to registered interests, so in case that there were multiple interests registered in the node it could be a bit difficult to filter there, so the option I was using, getting events by streamId model, was easier to handle than feed. Update: I tried to use feed, but I see that it only returns events related to the specific ceramic-one node but not to other nodes. So for example, if I have an interest registered in a stream that was not created in my node, if I get feed information, I would not get events from this stream/model created in different node.
Related to flight sql server makes sense but I was avoiding to use it because I am creating a distributed architecture with ceramic nodes, so it was easier and convenient to retrieve the information directly from the ceramic nodes than adding a flight sql server along each node.
Worst case scenario I can try to handle in the code the events received after using /experimental/events/model/{modelStreamId}, but would be great if there was a way to use resumeToken related to the last event or in case that the events were ordered by time or latest addition.
Just wanted to mention and correct me if I am missing something or in case you had any suggestion that I could miss.