dblock / slack-strava

(Re)Post Strava activities to Slack
https://slava.playplay.io
MIT License
37 stars 6 forks source link

Incorrect sync from Strava (activity n -1) #152

Closed tyketchum closed 1 year ago

tyketchum commented 1 year ago

When one user uploads an activity this morning, for example, Slava syncs their previous activity from two days ago instead of the activity from this morning. Any experience with this before?

dblock commented 1 year ago

There are a few things going on in the user activity sync. The sync tries to go back in this order activities_at || latest_activity_start_date || before_connected_to_strava_at || created_at. That brings data into the database, so at any point in time there may be some activities in the database that have not been posted.

Then, new activities are posted, picking the oldest one first.

Finally, when any activity is updated for a user, Strava sends a notification to Slava and the above happens. It also happens on a timer to catch up daily.

I think the bot went back to some activities that were in the database that weren't posted yet and it just happened that it was yesterday's. This can happen if the user disconnects their account and reconnects it later, for example.

Did this user's activities catch up eventually (expected) or are they permanently stuck in posting old activities (bug?)?

tyketchum commented 1 year ago

That makes a lot of sense - this user did disconnect their account and reconnect it later.

This user's activities did catch up - not sure if it helped, but the user dm'd Slava with "set sync false" then again with "set sync true"

Thank you for the response!

dblock commented 1 year ago

Yes it did. That's actually there exactly for the workaround to use when a user reconnects a million years later and has a bagillion activities catching up (I think I added some logic to avoid that too, but I forget ;). Take a look at what happens when the user does a set sync false in https://github.com/dblock/slack-strava/blob/master/slack-strava/models/user.rb#L361. Their (pending) activities are deleted and the time to sync from is reset to now.