TClark1011/bag-of-holding

Refactor "updatedAt" checking logic

Opened this issue · 0 comments

Right now, we use some middleware functionality on the "sheetRelatedProcedure" trpc object to make sure that whenever an element with a "sheetId" element is returned from a trpc mutation, we then go and update that sheet's updatedAt attribute. This makes sure that whenever we update any entity related to a sheet, it will also update parent sheet's updatedAt date. This is used, because on the client whenever we do an optimistic update, we increment the sheet's updatedAt, then when sheet data is fetched from the server, if that sheet data has an earlier updatedAt than we have in our client state, we know that server data is out of data and should not be saved into our client state.

We should refactor this to remove the use of the middleware, and instead give every sheet related entity an updatedAt field, and then to compare two sheet entities with all their related entities, we map through the sheet's own updatedAt attribute, as well as the updatedAt field's of all of the sheet's characters, items, and currencies, and then we find the most recent updatedAt, and use that.