[PR #4020] [MERGED] Invalidate count cache on entity update #4147

Closed
opened 2026-04-25 00:18:32 +02:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/advplyr/audiobookshelf/pull/4020
Author: @mikiher
Created: 2/21/2025
Status: Merged
Merged: 2/23/2025
Merged by: @advplyr

Base: masterHead: invalidate-count-cache-on-entity-update


📝 Commits (4)

  • e8b60de Invalidate count cache on entity update
  • 9d7f44f Fix RSS Feed Open query
  • d6b58c2 Revert "Invalidate count cache on entity update"
  • 364ccd8 Use count cache only when no filter is set

📊 Changes

2 files changed (+44 additions, -35 deletions)

View changed files

📝 server/utils/queries/libraryItemsBookFilters.js (+26 -22)
📝 server/utils/queries/libraryItemsPodcastFilters.js (+18 -13)

📄 Description

Brief summary

Invalidates the count cache in libraryItems(Book|Podcast)Filters when a book/podcast/episode is updated.

Which issue is fixed?

Fixes #4018 partially

In-depth Description

Up until now, the cache count was invalidated only when an item was created or destroyed. However, when a filter is applied to the library page and an item metadata is updated, the number of items returned by that filter might change. It's not easy to identify which of the cached counts change or not, so the whole count cache needs to be invalidated in this case as well.

I added hooks to invalidate the count cache after book/podcast/episode updates.

Note: an immediate update of the count and removal/addition of the updated book in the filtered view is preferred, but it is hard to identify when such a change requires resetEntities() to be called without actually running the count query again. So I left the client code as is (it is not a regression). That's why I said above that if fixes the bug partially

How have you tested this?

Set a filter on the library page, changed an item's metadata so that it should affect the filtered items count, and made sure that the count changes after the library page is reloaded, and no blank entries appear at the end.

Did this for both podcast and book libraries.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/advplyr/audiobookshelf/pull/4020 **Author:** [@mikiher](https://github.com/mikiher) **Created:** 2/21/2025 **Status:** ✅ Merged **Merged:** 2/23/2025 **Merged by:** [@advplyr](https://github.com/advplyr) **Base:** `master` ← **Head:** `invalidate-count-cache-on-entity-update` --- ### 📝 Commits (4) - [`e8b60de`](https://github.com/advplyr/audiobookshelf/commit/e8b60defb6b04fb3654208c5e9365bbdbcfcdbda) Invalidate count cache on entity update - [`9d7f44f`](https://github.com/advplyr/audiobookshelf/commit/9d7f44f73aca6157e7a4be28361c510200494ad1) Fix RSS Feed Open query - [`d6b58c2`](https://github.com/advplyr/audiobookshelf/commit/d6b58c2f10f66c5ef36fc720da2c901657b75021) Revert "Invalidate count cache on entity update" - [`364ccd8`](https://github.com/advplyr/audiobookshelf/commit/364ccd85fe0f9504c66cf7cf332c3534663d50fb) Use count cache only when no filter is set ### 📊 Changes **2 files changed** (+44 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `server/utils/queries/libraryItemsBookFilters.js` (+26 -22) 📝 `server/utils/queries/libraryItemsPodcastFilters.js` (+18 -13) </details> ### 📄 Description ## Brief summary Invalidates the count cache in libraryItems(Book|Podcast)Filters when a book/podcast/episode is updated. ## Which issue is fixed? Fixes #4018 partially ## In-depth Description Up until now, the cache count was invalidated only when an item was created or destroyed. However, when a filter is applied to the library page and an item metadata is updated, the number of items returned by that filter might change. It's not easy to identify which of the cached counts change or not, so the whole count cache needs to be invalidated in this case as well. I added hooks to invalidate the count cache after book/podcast/episode updates. _Note:_ an immediate update of the count and removal/addition of the updated book in the filtered view is preferred, but it is hard to identify when such a change requires `resetEntities()` to be called without actually running the count query again. So I left the client code as is (it is not a regression). That's why I said above that if fixes the bug partially ## How have you tested this? Set a filter on the library page, changed an item's metadata so that it should affect the filtered items count, and made sure that the count changes after the library page is reloaded, and no blank entries appear at the end. Did this for both podcast and book libraries. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2026-04-25 00:18:32 +02:00
adam closed this issue 2026-04-25 00:18:32 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/audiobookshelf#4147