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

Ensure we call ReconnectApp when the passed clientUpdateID is not in the DB #47582

Closed
iwiznia opened this issue Aug 16, 2024 · 19 comments
Closed
Assignees
Labels
Engineering Improvement Item broken or needs improvement. Monthly KSv2 Reviewing Has a PR in review

Comments

@iwiznia
Copy link
Contributor

iwiznia commented Aug 16, 2024

Context https://expensify.slack.com/archives/C03TQ48KC/p1723832372007299?thread_ts=1723826918.927409&cid=C03TQ48KC

Problem

Right now when the clientUpdateID is not in the DB because it got deleted already, we are just assuming you are up to date, but we really can't know that, there might be updates that you missed.

Solution

If we don't have the clientUpdateID in the DB we should instruct the client to call ReconnectApp to ensure they get all the data they might have missed

@iwiznia iwiznia added Engineering Daily KSv2 Improvement Item broken or needs improvement. labels Aug 16, 2024
Copy link

melvin-bot bot commented Aug 19, 2024

Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

@melvin-bot melvin-bot bot added the Overdue label Aug 19, 2024
@iwiznia iwiznia self-assigned this Aug 20, 2024
@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Aug 20, 2024
Copy link

melvin-bot bot commented Aug 23, 2024

@iwiznia Whoops! This issue is 2 days overdue. Let's get this updated quick!

Copy link

melvin-bot bot commented Aug 27, 2024

@iwiznia 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@danieldoglas danieldoglas self-assigned this Aug 29, 2024
@melvin-bot melvin-bot bot added Overdue and removed Overdue labels Aug 29, 2024
@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 4, 2024

Need to update all overdue issues and then will work on this

@melvin-bot melvin-bot bot removed the Overdue label Sep 4, 2024
@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 4, 2024

ok writing down the solution here:

  1. In auth, we will pass clientUpdateID to getPreviousUpdateID here
  2. At the beginning of getPreviousUpdateID we will check if clientUpdateID is in the DB, if it is not we will return -1
  3. In Auth class here if the response has accounts.X.lastUpdateID and previousUpdateID is -1, we will call AppInit::reconnectApp without $updateIDFrom
  4. This is the part that's unclear... we basically need to add them to the response, but not send them via pusher nor save them in the DB (so we don't want to call Push_API::queue) we basically want to include them in Onyx::getAccountOnyxUpdates so that they get added to the response here, so maybe we can convert the data to events and add them directly to Pusher_API::$sentEvents (which is what Onyx::getAccountOnyxUpdates uses). I think this should work, even if it is a little unconventional (because we did not actually sent the events)
  5. We would also save the fact we called ReconnectApp in a class variable in the Auth class and skip the behavior on step 3 by checking this variable

Thoughts? @danieldoglas

@danieldoglas
Copy link
Contributor

I'm OK with this logic, we only want to add the ReconnectApp for the caller.

IF we're doing it to async onyx updates, then I think we might need to send something that says "you should call reconnectApp from scratch"

Maybe it's time to introduce new custom actions we can send to the app?

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 5, 2024

IF we're doing it to async onyx updates,

We are not, since we don't have a clientUpdateID there

@danieldoglas
Copy link
Contributor

how are we dealing with cases where we can't find a previousUpdateID (so no updates at all for them) for an account that is receiving an async update?

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 5, 2024

Yesterday I thought about it and thought it was a non issue, but I don't know how I convinced myself of that 😂

I think there's 2 scenarios, both of them happen when we are in the GetMissingOnyxMessages flow:

  1. We find a previousUpdateID for you. I think there's no issue here. When you receive it either you apply it or if you don't have the previousUpdateID, call GetMissingOnyxMessages which will either download the missing updates or do a full reconnect if we don't have them
  2. We don't find a previousUpdateID and thus return -1. In this case we would have to run the same logic described in step 4 but with the main difference that we would need to track if we run that logic for each user in that same class. We would do that here

Does that make sense?

@danieldoglas
Copy link
Contributor

I don't think that's the best solution. That means we would send possibly sereal megabytes of updates through pusher for those users that do not have the previous updateID

I'd say we'd need to create a new type of onyx operation, something like reload, and send that operation with the update that is being sent. If they receive that operation, then we do a OpenApp in the app to reload everything.

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 5, 2024

Good point! That makes total sense, a ReconnectApp call can be huge and the users might not even have the app/web open.

But if we do that, wouldn't it make more sense to use that same onyx operation for the current user and simplify this whole thing? I think it would, because that way we would only have one way of handling this for both cases. Also while we could do what I described above for the current user and avoid the extra network roundtrip, this flow is basically the same as you are missing updates and need to do another call that we already have.

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 5, 2024

I just realized that a new onyx operation is not the right call. Calling an API command to do a full reconnect is not an onyx operation at all. Instead, we can use a new pusher event. Summarizing the updated solution that solves the problem for both current user and others:

  1. In auth, we will pass clientUpdateID to getPreviousUpdateID here
  2. At the beginning of getPreviousUpdateID we will check if clientUpdateID is in the DB, if it is not we will return 0 (same as we do when we find no updates)
  3. In Auth class here if the response has accounts.X.lastUpdateID and previousUpdateID is 0, we will queue pusher event appReload ensuring we set the event's pusherSocketID to 0 (this is so that the event is delivered to the user making the request and is not instead included in the response)
  4. We would also save the fact we queued this update in a class variable in the Auth class so we can avoid sending 2 events to the same user
  5. In app, we will subscribe to this new event like we do here
  6. And call App action reconnectApp

@danieldoglas
Copy link
Contributor

I think this makes sense. I'm just not fully sold on adding a new event/event subscription.

@danieldoglas
Copy link
Contributor

After talking to ioni, I agree we can create a new event.

Copy link

melvin-bot bot commented Sep 9, 2024

@iwiznia, @danieldoglas Whoops! This issue is 2 days overdue. Let's get this updated quick!

@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 10, 2024

Working on this. I have the PRs ready above. I need to test the other users case.

@melvin-bot melvin-bot bot removed the Overdue label Sep 10, 2024
@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Sep 11, 2024
@iwiznia
Copy link
Contributor Author

iwiznia commented Sep 11, 2024

Sent all PRs for review

@melvin-bot melvin-bot bot removed the Weekly KSv2 label Oct 4, 2024
Copy link

melvin-bot bot commented Oct 4, 2024

This issue has not been updated in over 15 days. @iwiznia, @danieldoglas eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@melvin-bot melvin-bot bot added the Monthly KSv2 label Oct 4, 2024
@iwiznia
Copy link
Contributor Author

iwiznia commented Oct 7, 2024

This was done way back

@iwiznia iwiznia closed this as completed Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engineering Improvement Item broken or needs improvement. Monthly KSv2 Reviewing Has a PR in review
Projects
Development

No branches or pull requests

2 participants