Optimize database queries to reduce initial application load time

This commit is contained in:
aditya.chandel
2025-06-02 14:52:17 -06:00
parent baff1bc9b5
commit 7a4a401e87
37 changed files with 483 additions and 268 deletions
@@ -295,12 +295,6 @@ export class BookBrowserComponent implements OnInit, AfterViewInit {
return filterValues.every(val => book.metadata?.categories?.includes(val));
case 'publisher':
return filterValues.every(val => book.metadata?.publisher === val);
case 'award':
return filterValues.every(val =>
book.metadata?.awards?.some(
award => award.name === val.name && award.designation === 'WINNER'
)
);
case 'series':
return filterValues.every(val => book.metadata?.seriesName === val);
default:
@@ -51,7 +51,6 @@ export class BookFilterComponent implements OnInit {
author: this.getFilterStream((book: Book) => book.metadata?.authors.map((name) => ({id: name, name})) || [], 'id', 'name'),
category: this.getFilterStream((book: Book) => book.metadata?.categories.map((name) => ({id: name, name})) || [], 'id', 'name'),
series: this.getFilterStream((book) => (book.metadata?.seriesName ? [{id: book.metadata.seriesName, name: book.metadata.seriesName}] : []), 'id', 'name'),
award: this.getFilterStream((book) => book.metadata?.awards?.filter((award) => award.designation === 'WINNER'), 'name', 'name'),
publisher: this.getFilterStream((book) => (book.metadata?.publisher ? [{id: book.metadata.publisher, name: book.metadata.publisher}] : []), 'id', 'name'),
};
this.filterTypes = Object.keys(this.filterStreams);
@@ -129,14 +129,57 @@
</div>
<div *ngIf="userService.userState$ | async as userData" class="pl-6 pt-4 flex flex-row w-full gap-4">
<p-splitbutton label="Read" icon="pi pi-book" [model]="readMenuItems" (onClick)="read(metadata.bookId, 'ngx')" severity="info"/>
<p-button label="Assign Shelf" icon="pi pi-folder" severity="info" outlined (onClick)="assignShelf(metadata.bookId)"></p-button>
<p-button *ngIf="userData.permissions.canDownload || userData.permissions.admin" label="Download" icon="pi pi-download" severity="info" outlined
(onClick)="download(metadata.bookId)"></p-button>
<p-splitbutton *ngIf="userData.permissions.canEmailBook || userData.permissions.admin" label="Quick Send" icon="pi pi-send" [model]="emailMenuItems"
(onClick)="quickSend(metadata.bookId)" outlined severity="info"/>
<p-splitbutton *ngIf="userData.permissions.canEditMetadata || userData.permissions.admin" label="Quick Refresh" icon="pi pi-bolt" [model]="refreshMenuItems"
(onClick)="quickRefresh(metadata.bookId)" outlined severity="info"/>
<p-splitbutton
*ngIf="book!.bookType === 'PDF'"
label="Read"
icon="pi pi-book"
[model]="readMenuItems"
(onClick)="read(metadata.bookId, 'ngx')"
severity="info"/>
<p-button
*ngIf="book!.bookType !== 'PDF'"
label="Read"
icon="pi pi-book"
(onClick)="read(metadata.bookId, undefined)"
severity="info"/>
<p-button
label="Assign Shelf"
icon="pi pi-folder"
severity="info"
outlined
(onClick)="assignShelf(metadata.bookId)">
</p-button>
<p-button
*ngIf="userData.permissions.canDownload || userData.permissions.admin"
label="Download"
icon="pi pi-download"
severity="info"
outlined
(onClick)="download(metadata.bookId)">
</p-button>
<p-splitbutton
*ngIf="userData.permissions.canEmailBook || userData.permissions.admin"
label="Quick Send"
icon="pi pi-send"
[model]="emailMenuItems"
(onClick)="quickSend(metadata.bookId)"
outlined
severity="info">
</p-splitbutton>
<p-splitbutton
*ngIf="userData.permissions.canEditMetadata || userData.permissions.admin"
label="Quick Refresh"
icon="pi pi-bolt"
[model]="refreshMenuItems"
(onClick)="quickRefresh(metadata.bookId)"
outlined
severity="info">
</p-splitbutton>
</div>
</div>
</div>
@@ -154,8 +154,8 @@ export class MetadataViewerComponent implements OnInit, OnChanges {
this.isExpanded = !this.isExpanded;
}
read(bookId: number | undefined, reader: "ngx" | "streaming"): void {
this.bookService.readPdf(bookId!, reader);
read(bookId: number | undefined, reader: "ngx" | "streaming" | undefined): void {
this.bookService.readBook(bookId!, reader);
}
getAuthorNames(authors: string[]): string {
@@ -59,7 +59,6 @@ export interface BookMetadata {
coverUpdatedOn?: string;
authors: string[];
categories: string[];
awards?: Award[];
provider?: string;
providerBookId?: string;
thumbnailUrl?: string | null;
@@ -88,19 +87,11 @@ export interface BookMetadata {
coverUpdatedOnLocked?: boolean;
authorsLocked?: boolean;
categoriesLocked?: boolean;
awardsLocked?: boolean;
coverLocked?: boolean;
[key: string]: any;
}
export interface Award {
name: string;
category: string;
designation: string;
awardedAt: string;
}
export interface PdfViewerSetting {
zoom: string | number;
spread: 'off' | 'even' | 'odd';
@@ -116,47 +116,33 @@ export class BookService {
this.bookStateSubject.next({...currentState, books: updatedBooks});
}
readPdf(bookId: number, reader: "ngx" | "streaming") {
const currentBooks = this.bookStateSubject.value.books;
const book = currentBooks?.find(book => book.id === bookId);
if (book) {
if (book.bookType === "PDF") {
if (reader === "ngx") {
const url = `/pdf-viewer/book/${book.id}`;
window.open(url, '_blank');
} else {
const url = `/cbx-viewer/book/${book.id}`;
window.open(url, '_blank');
}
this.updateLastReadTime(book.id);
}
} else {
readBook(bookId: number, reader?: "ngx" | "streaming"): void {
const book = this.bookStateSubject.value.books?.find(b => b.id === bookId);
if (!book) {
console.error('Book not found');
return;
}
}
readBook(bookId: number): void {
const currentBooks = this.bookStateSubject.value.books;
const book = currentBooks?.find(book => book.id === bookId);
if (book) {
if (book.bookType === "PDF") {
const url = `/pdf-viewer/book/${book.id}`;
window.open(url, '_blank');
this.updateLastReadTime(book.id);
} else if (book.bookType === "EPUB") {
const url = `/epub-viewer/book/${book.id}`;
window.open(url, '_blank');
this.updateLastReadTime(book.id);
} else if (book.bookType === "CBX") {
const url = `/cbx-viewer/book/${book.id}`;
window.open(url, '_blank');
this.updateLastReadTime(book.id);
} else {
let url: string | null = null;
switch (book.bookType) {
case "PDF":
url = !reader || reader === "ngx"
? `/pdf-viewer/book/${book.id}`
: `/cbx-viewer/book/${book.id}`;
break;
case "EPUB":
url = `/epub-viewer/book/${book.id}`;
break;
case "CBX":
url = `/cbx-viewer/book/${book.id}`;
break;
default:
console.error('Unsupported book type:', book.bookType);
}
} else {
console.error('Book not found');
return;
}
window.open(url, '_blank');
this.updateLastReadTime(book.id);
}
searchBooks(query: string): Book[] {