refactor(books): migrate services off the old book cache (#2218)

This commit is contained in:
Alex
2026-09-21 13:01:53 +01:00
committed by GitHub
parent 2c9581f2c1
commit 25bfff3e31
9 changed files with 167 additions and 95 deletions
@@ -10,7 +10,7 @@ import {CacheStorageService} from '../../../shared/service/cache-storage.service
import {LocalSettingsService} from '../../../shared/service/local-settings.service';
import {TranslocoService} from '@jsverse/transloco';
import {QueryClient} from '@tanstack/angular-query-experimental';
import {patchBookInCacheWith, patchBooksInCache, removeBooksFromCache} from './book-query-cache';
import {patchAttachedBookFilesInCache, patchBookInCacheWith, upsertBooksInCache} from './legacy-book-cache';
@Injectable({
providedIn: 'root',
@@ -168,7 +168,7 @@ export class BookFileService {
detachBookFile(bookId: number, fileId: number, copyMetadata: boolean): Observable<DetachBookFileResponse> {
return this.http.post<DetachBookFileResponse>(`${this.url}/${bookId}/files/${fileId}/detach`, {copyMetadata}).pipe(
tap(response => {
patchBooksInCache(this.queryClient, [response.sourceBook, response.newBook]);
upsertBooksInCache(this.queryClient, [response.sourceBook, response.newBook]);
this.messageService.add({
severity: 'success',
summary: this.t.translate('metadata.viewer.toast.detachFileSuccessSummary'),
@@ -196,8 +196,11 @@ export class BookFileService {
moveFiles
}).pipe(
tap(response => {
patchBooksInCache(this.queryClient, [response.updatedBook]);
removeBooksFromCache(this.queryClient, response.deletedSourceBookIds);
patchAttachedBookFilesInCache(
this.queryClient,
response.updatedBook,
response.deletedSourceBookIds,
);
this.messageService.add({
severity: 'success',
summary: this.t.translate('book.bookService.toast.filesAttachedSummary'),