Update "last visited" when gameboard viewed - #817
Conversation
When a user requests a gameboard, if it is already saved to their My Saved Decks, update the last_visited date in user_gameboards. This introduces a new DB method rather than reusing `createOrUpdateUserLinkToGameboard` both for clarity and to avoid the overhead of trying & failing to insert a new row, since we know we have the `ON CONFLICT` case.
If this update somehow fails, it shouldn't prevent the user from loading the gameboard.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #817 +/- ##
==========================================
+ Coverage 40.97% 41.06% +0.09%
==========================================
Files 550 550
Lines 23555 23621 +66
Branches 2837 2851 +14
==========================================
+ Hits 9652 9701 +49
- Misses 13032 13043 +11
- Partials 871 877 +6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
I was just looking back to try to find out why this used to be working but stopped, and found out that we used to call the createOrUpdateUserLinkToGameboard method when visiting a page as well as on linking it (which we still do). This new approach of using a separate method for linking and visiting seems much more sensible, but it remains that this createOrUpdateUserLinkToGameboard method still talks about and has the functionality for just updating last_visited rather than setting the whole row.
This PR could go in as-is, but I'd rather we also clean up that other code while we're at it so it's explicitly just for linking, and this is explicitly just for visiting.
(This also highlights that there also used to be a DB write every time a saved gameboard was loaded in the past, which seemed to be fine, so I don't think there should be any problem with doing it again)
|
Hmm. I think there are still some (admittedly niche) cases where we still want the update behaviour as a fallback for creating a new link. For example, when a user renames a gameboard ( This also means if there's anywhere else where we might call I don't feel strongly about this though, perhaps it would be neater to always decide whether we're creating or updating at the manager level rather than relying on a fallback at the DB layer. Happy to change it if you still prefer that approach! |
|
@axlewin Your example of Even if it were more widely available, I think that renaming/editing a gameboard is a distinct action from visiting it and that I wouldn't be surprised for a "Last visited on" to not update if I hadn't actually done any visiting. There don't seem to be any other ways for the function to be called beyond an initial link and this renaming currently, but even if there were I still support the idea of separating the use-cases of the functions at the manager level anyway - so yes, I still prefer my above approach. |
Treat persisting a gameboard to permanent storage, saving a gameboard to a user's boards, and updating the "last visited" date as distinct operations.
sjd210
left a comment
There was a problem hiding this comment.
I prefer this split, and think that this still works so 👍
Makes the "last visited" date on a gameboard (as displayed on My Saved Decks) actually update when the gameboard is viewed.
This does introduce an extra DB write every time a saved gameboard is loaded, but I don't see a way around that if we want "last visited" to work.