Skip to content

Missing subquery() call in StreamChat.Chat.Message.Query.previous_n/3Β #3

@beneckimateusz

Description

@beneckimateusz

While reading the article I noticed that something is off with previous_n, because it's supposed to return the messages ordered ascending by inserted_at, yet in the live view oldest_message_id was being assigned to the last element of the result, not the first one (as it would logically make sense).

I narrowed down the problem to a missing subquery() call (though properly used in for_room/2) that influenced these misconceptions down the road.

It's worth noting that stream_batch_insert will behave incorrectly once previous_n is fixed because it will insert these previous messages to the beginning of the stream in reversed order. Hence, if it receives at: 0 in opts, we should reverse the items before using Enum.reduce over it.

I believe it's important to raise that issue since the main purpose of this blog post is to showcase the stream feature yet an inconvenient bug crept into the code πŸ˜„

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions