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

[refs #3210] remove unnecessary reads from Realm for messages #3265

Merged
merged 1 commit into from
Feb 21, 2018

Conversation

dmitryn
Copy link
Contributor

@dmitryn dmitryn commented Feb 8, 2018

Addresses #3210

Summary:

Replace realm read for messages data with app-db read as we don't need to touch realm since data is already in app-db.

Testing notes:

App behavior should not change. Code changed related to messages:

  • intro/account creation messages
  • regular messages

status: ready

@dmitryn dmitryn self-assigned this Feb 8, 2018
@dmitryn dmitryn added this to REVIEW in Pipeline for QA via automation Feb 8, 2018
(get-stored-message message-id))))))))
(not (or (get deleted-chats chat-identifier)
(get messages message-id)
(get not-loaded-message-ids message-id))))))
Copy link
Contributor

@janherich janherich Feb 8, 2018

Choose a reason for hiding this comment

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

I'm afraid we can't get rid of the realm message read in this case, the following scenario is problematic:
You have some deleted chat and message for that chat get re-delivered to you (because you didn't ack before, or any other reason, I generally found the re-delivery quite unreliable and you always how to defend against message with same id delivered to you again).
Now we now that the message is for deleted chat (as deleted chat ids are loaded on startup) but we don't know if it's message not received before (in which case, we have to restore the chat and add message, otherwise once you delete 1-1 chat, you will never be able to have conversation with given contact anymore) or already received message (so nothing is restored and we ignore the message).
The reason for it is that for deleted chats, we don't load their message ids into db at startup.

I did it that way originally because:

  1. It's a quite rare case (re-delivery of message for deleted chat) so the perf impact of reading from realm (only in that specific case) is probably negligible overall
  2. Having :not-loaded-message-ids for deleted chats always in db seemed like a waste

Maybe point 2) is open to discussion and it's nothing horrible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@janherich good call. Returned that logic back.

message (or (get-in db message-db-path)
(and (get (:not-loaded-message-ids db) message-identifier)
(get-stored-message message-identifier)))]
message (get-in db message-db-path)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar point like before, we only have 20 messages loaded for each chat when it's opened (more when one scrolls up), so whenever we receive update for some message which is not yet loaded (second and condition in the original expression), we should update it as well, otherwise we ignore status updates for just little bit older messages.

@janherich
Copy link
Contributor

@dmitryn now it's good, but please return cofx registration re-frame/reg-cofx for :get-stored-message as well

@dmitryn
Copy link
Contributor Author

dmitryn commented Feb 8, 2018

@janherich it was returned. please take a look

@dmitryn
Copy link
Contributor Author

dmitryn commented Feb 8, 2018

@janherich sorry, haven't push that yet.

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
@flexsurfer flexsurfer merged commit d799396 into develop Feb 21, 2018
Pipeline for QA automation moved this from MERGE to DONE Feb 21, 2018
@rasom rasom deleted the 3146-realm-reads-part-3 branch April 19, 2018 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants