fix: latest tweets retrieval optimization is unpredictable #234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
getTweets
does not always return results in a predictable order, which means that the first tweet in not necessarily the latest one. This breaks the synchronization optimization because it relies on this assumption.This fix reverses the implementation for this optimization: instead of preventing the sync when the latest tweet if cached, we prevent the sync by default but allow it to run if we find that any of the ${LATEST_TWEETS_COUNT} tweets is not cached.
Notes
latestTweets
could have been an option too, I didn't do that because reversing the logic felt more future-proof (who knows whatever they might break in the future). However I see no reason why it wouldn't work by sorting on the tweet ID, if you feel this should better be implemented this way, please tell me!