Skip to content

The same data in real-time and not #16

@itsezlife

Description

@itsezlife

I need to make specific data both real-time and not. I have not found in docs what to do if the same data should be real-time in certain cases and globally accessible but should not affect the data that is real-time.

In the first screen "User profile" where I stream real-time posts, likes and comments of currently authenticated user, that actually made them, filtered in PowerSync by token parameters user id. It compares posts author id and current authenticated user id, takes these posts ids and in data returns all posts with these ids, likes of these posts and comments. This section works perfectly fine, but when it takes to combine with the second, it becomes tricky.

In the second screen "Feed" I need to get all posts globally by all users, where posts need to be paginated with infinity scroll and fetched as user scroll. New data that is posted by other users should not be appeared in real-time in "Feed", however it is only when someone else posts something. So, whenever you are the one who post, newly created post should be in real-time displayed at the top of the all posts that was fetched. In the addition, likes should not be changed in the "Feed" whenever someone else likes the post, but when you do this, right in the "Feed" view, or from anywhere else, it should be changed in real-time BUT only for you and synced.

Overall, I have no idea how to combine all of these and makes it working in sync rules. Separately, first screen is implemented and I have no problem with it. But now, when I began to implement second screen I was stuck.

Here are current sync rules that I am using. I have implemented only streaming the data that currently authenticated user owns, so with the rest I need help.

bucket_definitions:
  user_profiles:
        parameters:
            select id as profile_id from profiles where id = token_parameters.user_id
        data:
           - select * from profiles where id = bucket.profile_id
  # Makes all posts, likes and comments real-time where publisher user id equals 
  # to current authenticated user id from token parameters.
  user_posts:
        parameters:
            select id as post_id from posts where user_id = token_parameters.user_id
        data:
            - select * from posts where posts.id = bucket.post_id
            - select * from comments where comments.post_id = bucket.post_id
            - select * from likes where likes.post_id = bucket.post_id

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions