Searching while updating series now uses latest published date of the series as a stop reference.
This commit is contained in:
@ -28,7 +28,7 @@ export class LibraryConsumer extends WorkerHost {
|
|||||||
|
|
||||||
if (job.name == 'new_series') {
|
if (job.name == 'new_series') {
|
||||||
const series: CreateSeriesSubscriptionJobDto = job.data;
|
const series: CreateSeriesSubscriptionJobDto = job.data;
|
||||||
const books = await this.search(job, series, false);
|
const books = await this.search(job, series, null);
|
||||||
|
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
for (let book of books) {
|
for (let book of books) {
|
||||||
@ -54,7 +54,8 @@ export class LibraryConsumer extends WorkerHost {
|
|||||||
const series: CreateSeriesSubscriptionJobDto = job.data;
|
const series: CreateSeriesSubscriptionJobDto = job.data;
|
||||||
const existingBooks = await this.library.getBooksFromSeries(series);
|
const existingBooks = await this.library.getBooksFromSeries(series);
|
||||||
const existingVolumes = existingBooks.map(b => b.volume);
|
const existingVolumes = existingBooks.map(b => b.volume);
|
||||||
const books = await this.search(job, series, true);
|
const lastPublishedBook = existingBooks.sort((a, b) => b.publishedAt.getTime() - a.publishedAt.getTime())[0];
|
||||||
|
const books = await this.search(job, series, lastPublishedBook?.publishedAt);
|
||||||
|
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
for (let book of books) {
|
for (let book of books) {
|
||||||
@ -99,10 +100,10 @@ export class LibraryConsumer extends WorkerHost {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async search(job: Job, series: CreateSeriesSubscriptionJobDto, newest: boolean): Promise<{ result: BookSearchResultDto, score: number }[]> {
|
private async search(job: Job, series: CreateSeriesSubscriptionJobDto, after: Date|null): Promise<{ result: BookSearchResultDto, score: number }[]> {
|
||||||
let context = this.provider.generateSearchContext(series.provider, series.title) as GoogleSearchContext;
|
let context = this.provider.generateSearchContext(series.provider, series.title) as GoogleSearchContext;
|
||||||
context.maxResults = '40';
|
context.maxResults = '40';
|
||||||
if (newest) {
|
if (after) {
|
||||||
context.orderBy = 'newest';
|
context.orderBy = 'newest';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,7 +124,7 @@ export class LibraryConsumer extends WorkerHost {
|
|||||||
}
|
}
|
||||||
context = context.next();
|
context = context.next();
|
||||||
job.updateProgress(pageSearchedCount * 5);
|
job.updateProgress(pageSearchedCount * 5);
|
||||||
} while (results.length >= context.maxResults && (!newest || unhelpfulResultsCount < 3));
|
} while (results.length >= context.maxResults && (!after || after < results[results.length - 1].publishedAt));
|
||||||
|
|
||||||
// Sort & de-duplicate the entries received.
|
// Sort & de-duplicate the entries received.
|
||||||
const books = related.map(book => this.toScore(book, series))
|
const books = related.map(book => this.toScore(book, series))
|
||||||
@ -131,7 +132,6 @@ export class LibraryConsumer extends WorkerHost {
|
|||||||
.filter((_, index, arr) => index == 0 || arr[index - 1].result.volume != arr[index].result.volume);
|
.filter((_, index, arr) => index == 0 || arr[index - 1].result.volume != arr[index].result.volume);
|
||||||
job.updateProgress(25);
|
job.updateProgress(25);
|
||||||
|
|
||||||
|
|
||||||
this.logger.debug({
|
this.logger.debug({
|
||||||
class: LibraryConsumer.name,
|
class: LibraryConsumer.name,
|
||||||
method: this.search.name,
|
method: this.search.name,
|
||||||
|
@ -31,6 +31,7 @@ import { LibraryController } from './library.controller';
|
|||||||
HttpModule,
|
HttpModule,
|
||||||
ProvidersModule,
|
ProvidersModule,
|
||||||
],
|
],
|
||||||
|
exports: [LibraryService],
|
||||||
providers: [LibraryService, BooksService, SeriesService, LibraryConsumer],
|
providers: [LibraryService, BooksService, SeriesService, LibraryConsumer],
|
||||||
controllers: [LibraryController]
|
controllers: [LibraryController]
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user