[Bug]: LibraryItem updatedAt field is not updated after media changes #1719

Closed
opened 2026-04-24 23:55:56 +02:00 by adam · 4 comments
Owner

Originally created by @mikiher on GitHub (Feb 7, 2024).

Describe the issue

After a updating a book's metadata or cover, the corresponding libraryItem database record "updatedAt" field does not get updated.

I'm not sure in what ways this affects the current code, but it blocks me from implementing client-side cover image caching, because that feature depends on an up-to-date updatedAt timestamp for cache-busting.

Steps to reproduce the issue

  1. Open Chrome Dev Tools and select the Network tab
  2. Go to ABS library home page
  3. On the Network tab: Open http://{host}:{port}/api/libraries/{lib_id}/personalized?include=rssfeed,numEpisodesIncomplete
  4. On the Network tab: Select preview, then open the first book on the first shelf (0->entities->0), and record the updatedAt value.
  5. In ABS, open the Details tab for that book.
  6. Change a metadata field for a book (e.g. ASIN)
  7. Save and close the tab
  8. Reload the home page
  9. Repeat steps 3 and 4.

Expected: updatedAt value changed.
Actual: updatedAt value remained the same.

Audiobookshelf version

v2.7.2

How are you running audiobookshelf?

Windows Tray App

Originally created by @mikiher on GitHub (Feb 7, 2024). ### Describe the issue After a updating a book's metadata or cover, the corresponding libraryItem database record "updatedAt" field does not get updated. I'm not sure in what ways this affects the current code, but it blocks me from implementing client-side cover image caching, because that feature depends on an up-to-date updatedAt timestamp for cache-busting. ### Steps to reproduce the issue 1. Open Chrome Dev Tools and select the Network tab 2. Go to ABS library home page 3. On the Network tab: Open http://{host}:{port}/api/libraries/{lib_id}/personalized?include=rssfeed,numEpisodesIncomplete 4. On the Network tab: Select preview, then open the first book on the first shelf (0->entities->0), and record the updatedAt value. 5. In ABS, open the Details tab for that book. 6. Change a metadata field for a book (e.g. ASIN) 7. Save and close the tab 8. Reload the home page 9. Repeat steps 3 and 4. Expected: updatedAt value changed. Actual: updatedAt value remained the same. ### Audiobookshelf version v2.7.2 ### How are you running audiobookshelf? Windows Tray App
adam added the bug label 2026-04-24 23:55:56 +02:00
adam closed this issue 2026-04-24 23:55:56 +02:00
Author
Owner

@mikiher commented on GitHub (Feb 7, 2024):

Analysis:

ABS code does modify the updatedAt value of the updated libraryItem (see here), however there are a couple of issues here:

  1. updatedAt is not included in the list of fields extracted from the libraryItem object for update (see here)
  2. Even after fixing 1 by adding updatedAt to the list above, it is still not updated. This is because it is a special auto-generated field, and normally is only updated by sequelize if the record was actually changed in the database. In this case the LibraryItem record in the LibraryItems table did not change (what did change is the associated Book record in Books table, but that is not a change in the LibraryItem record), and therefore updatedAt was not modifed.

After some digging it looks like the solution for 2 is to add the following to server.models.LibraryItem.fullUpdateFromOld():
libraryItemExpanded.changed('updatedAt', true)
This marks the updatedAt column as dirty and forces sequelize to update it even if there are no other updates to the record (however, the actual timestamp that will be written is still not the one passed to update() - it is still automatically generated by sequelize - but it will at least be updated).

Note: I've seen the use of modifying updatedAt to mark changes in other places in the code. Those need to be checked as well.

@mikiher commented on GitHub (Feb 7, 2024): Analysis: ABS code does modify the updatedAt value of the updated libraryItem ([see here](https://github.com/advplyr/audiobookshelf/blob/432e25565e9a4aca43d9c3194f7babe89eb6206b/server/controllers/LibraryItemController.js#L151)), however there are a couple of issues here: 1. updatedAt is not included in the list of fields extracted from the libraryItem object for update ([see here](https://github.com/advplyr/audiobookshelf/blob/432e25565e9a4aca43d9c3194f7babe89eb6206b/server/models/LibraryItem.js#L385)) 2. Even after fixing 1 by adding updatedAt to the list above, it is still not updated. This is because it is a special auto-generated field, and normally is only updated by sequelize if the record was actually changed in the database. In this case the LibraryItem record in the LibraryItems table *did not* change (what did change is the associated Book record in Books table, but that *is not* a change in the LibraryItem record), and therefore updatedAt was not modifed. After some digging it looks like the solution for 2 is to add the following to `server.models.LibraryItem.fullUpdateFromOld()`: ` libraryItemExpanded.changed('updatedAt', true) ` This marks the updatedAt column as dirty and forces sequelize to update it even if there are no other updates to the record (however, the actual timestamp that will be written is still not the one passed to update() - it is still automatically generated by sequelize - but it will at least be updated). Note: I've seen the use of modifying updatedAt to mark changes in other places in the code. Those need to be checked as well.
Author
Owner

@advplyr commented on GitHub (Feb 18, 2024):

I recently had to make an update for the mobile app to PlaybackSession to allow the mobile app to set the updatedAt. For this adding silent: true did the trick.
https://sequelize.org/api/v6/class/src/model.js~model#static-method-create

@advplyr commented on GitHub (Feb 18, 2024): I recently had to make an update for the mobile app to `PlaybackSession` to allow the mobile app to set the `updatedAt`. For this adding `silent: true` did the trick. https://sequelize.org/api/v6/class/src/model.js~model#static-method-create
Author
Owner

@mikiher commented on GitHub (Feb 18, 2024):

This may have been enough for that case, but it does not work here (and I did try it), because of point 2 above - the record won't be updated if there are no other "real" changes in it (by "real" I mean changes to non-auto-generated fields) - and since the "real" changes only happen in the Book table (and someimtes not even there), the LibraryItem table has no "real" changes, and is therefore not updated.

The only way to force an update of the updatedAt column is to "touch" it using changed method described above.

@mikiher commented on GitHub (Feb 18, 2024): This may have been enough for that case, but it does not work here (and I did try it), because of point 2 above - the record won't be updated if there are no other "real" changes in it (by "real" I mean changes to non-auto-generated fields) - and since the "real" changes only happen in the Book table (and someimtes not even there), the LibraryItem table has no "real" changes, and is therefore not updated. The only way to force an update of the updatedAt column is to "touch" it using `changed` method described above.
Author
Owner

@advplyr commented on GitHub (Mar 17, 2024):

Fixed in v2.8.1

@advplyr commented on GitHub (Mar 17, 2024): Fixed in [v2.8.1](https://github.com/advplyr/audiobookshelf/releases/tag/v2.8.1)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#1719