perf: Optimize Novel Covers, Lists, and Chapter Groups
This commit is contained in:
@@ -24,7 +24,7 @@ import { getString } from '@strings/translations';
|
||||
import { NOVEL_STORAGE } from '@utils/Storages';
|
||||
import { dbManager } from '@database/db';
|
||||
import { chapterSchema, novelSchema } from '@database/schema';
|
||||
import NativeFile from '@modules/native-file'
|
||||
import NativeFile from '@modules/native-file';
|
||||
import { ChapterFilterKey, ChapterOrderKey } from '@database/constants';
|
||||
import { chapterFilterToSQL, chapterOrderToSQL } from '@database/utils/parser';
|
||||
import { castInt } from '@database/manager/manager';
|
||||
@@ -235,8 +235,11 @@ export const increaseTimeSpent = async (
|
||||
timeSpent: number,
|
||||
): Promise<void> => {
|
||||
await dbManager.write(async tx => {
|
||||
await tx.update(chapterSchema)
|
||||
.set({ timeSpent: sql`COALESCE(${chapterSchema.timeSpent}, 0) + ${timeSpent}` })
|
||||
await tx
|
||||
.update(chapterSchema)
|
||||
.set({
|
||||
timeSpent: sql`COALESCE(${chapterSchema.timeSpent}, 0) + ${timeSpent}`,
|
||||
})
|
||||
.where(eq(chapterSchema.id, chapterId))
|
||||
.run();
|
||||
});
|
||||
@@ -747,10 +750,7 @@ export const getNovelDownloadedChapters = async (
|
||||
eq(chapterSchema.isDownloaded, true),
|
||||
),
|
||||
)
|
||||
.orderBy(
|
||||
asc(castInt(chapterSchema.page)),
|
||||
asc(chapterSchema.position),
|
||||
)
|
||||
.orderBy(asc(castInt(chapterSchema.page)), asc(chapterSchema.position))
|
||||
.$dynamic();
|
||||
|
||||
if (startPosition !== undefined && endPosition !== undefined) {
|
||||
@@ -764,6 +764,7 @@ export const getUpdatedOverviewFromDb = async () =>
|
||||
dbManager
|
||||
.select({
|
||||
novelId: novelSchema.id,
|
||||
pluginId: novelSchema.pluginId,
|
||||
novelName: novelSchema.name,
|
||||
novelCover: novelSchema.cover,
|
||||
novelPath: novelSchema.path,
|
||||
@@ -782,6 +783,7 @@ export const getUpdatedOverviewFromDb = async () =>
|
||||
export const getDetailedUpdatesFromDb = async (
|
||||
novelId: number,
|
||||
onlyDownloadableChapters?: boolean,
|
||||
updateDate?: string,
|
||||
): Promise<Update[]> => {
|
||||
return dbManager
|
||||
.select({
|
||||
@@ -800,6 +802,9 @@ export const getDetailedUpdatesFromDb = async (
|
||||
onlyDownloadableChapters
|
||||
? eq(chapterSchema.isDownloaded, true)
|
||||
: isNotNull(chapterSchema.updatedTime),
|
||||
updateDate
|
||||
? eq(sql<string>`DATE(${chapterSchema.updatedTime})`, updateDate)
|
||||
: undefined,
|
||||
),
|
||||
)
|
||||
.orderBy(desc(chapterSchema.updatedTime))
|
||||
|
||||
@@ -1267,6 +1267,26 @@ describe('ChapterQueries', () => {
|
||||
|
||||
expect(result.every(c => c.isDownloaded === true)).toBe(true);
|
||||
});
|
||||
|
||||
it('should filter updates by their overview date', async () => {
|
||||
const testDb = getTestDb();
|
||||
const novelId = await insertTestNovel(testDb, { inLibrary: true });
|
||||
await insertTestChapter(testDb, novelId, {
|
||||
updatedTime: '2024-01-01 10:00:00',
|
||||
});
|
||||
await insertTestChapter(testDb, novelId, {
|
||||
updatedTime: '2024-01-02 10:00:00',
|
||||
});
|
||||
|
||||
const result = await getDetailedUpdatesFromDb(
|
||||
novelId,
|
||||
false,
|
||||
'2024-01-01',
|
||||
);
|
||||
|
||||
expect(result).toHaveLength(1);
|
||||
expect(result[0]?.updatedTime).toBe('2024-01-01 10:00:00');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isChapterDownloaded', () => {
|
||||
|
||||
@@ -68,7 +68,9 @@ export interface Update extends ChapterInfo {
|
||||
|
||||
export interface UpdateOverview {
|
||||
novelId: number;
|
||||
pluginId: string;
|
||||
novelName: string;
|
||||
novelPath: string;
|
||||
updateDate: string;
|
||||
updatesPerDay: number;
|
||||
novelCover: string | null;
|
||||
@@ -107,9 +109,9 @@ export interface LibraryStats {
|
||||
timeSpent: number;
|
||||
}[];
|
||||
topCategoriesByTimeSpent?: {
|
||||
id: number;
|
||||
name: string;
|
||||
timeSpent: number;
|
||||
id: number;
|
||||
name: string;
|
||||
timeSpent: number;
|
||||
}[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user