From 8f9541579762f5beb0d9181cde0e8122dee2624d Mon Sep 17 00:00:00 2001 From: Alexandr Velikiy <39257464+VargBurz@users.noreply.github.com> Date: Wed, 11 Sep 2019 14:45:42 +0300 Subject: [PATCH] Error: Can`t find cache for analytic unit #772 (#776) --- server/src/models/analytic_unit_cache_model.ts | 7 +++++-- server/src/models/segment_model.ts | 16 +++++++++------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server/src/models/analytic_unit_cache_model.ts b/server/src/models/analytic_unit_cache_model.ts index 0be76cb..a698c93 100644 --- a/server/src/models/analytic_unit_cache_model.ts +++ b/server/src/models/analytic_unit_cache_model.ts @@ -49,8 +49,11 @@ export class AnalyticUnitCache { return 3 * MILLISECONDS_IN_INDEX; } - public getTimeStep(): number { - return this.data.timeStep; + public get timeStep(): number | undefined { + if(this.data !== undefined) { + return this.data.timeStep; + } + return undefined; } } diff --git a/server/src/models/segment_model.ts b/server/src/models/segment_model.ts index ee19920..b672781 100644 --- a/server/src/models/segment_model.ts +++ b/server/src/models/segment_model.ts @@ -151,10 +151,6 @@ export async function mergeAndInsertSegments(segments: Segment[]): Promise<{ } const cache = await AnalyticUnitCache.findById(analyticUnitId); - if(cache === null) { - throw new Error('Can`t find cache for analytic unit ' + analyticUnitId); - } - const detector = unit.detectorType; let segmentIdsToRemove: SegmentId[] = []; @@ -180,10 +176,16 @@ export async function mergeAndInsertSegments(segments: Segment[]): Promise<{ deleted: segment.deleted }); } else { - const timeStep = cache.getTimeStep(); + let intersectionRangeExtension = 0; + if(cache !== null) { + const timeStep = cache.timeStep; + if(timeStep !== undefined) { + intersectionRangeExtension = timeStep; + } + } intersectedSegments = await findMany(analyticUnitId, { - to: { $gte: segment.from - timeStep }, - from: { $lte: segment.to + timeStep }, + to: { $gte: segment.from - intersectionRangeExtension }, + from: { $lte: segment.to + intersectionRangeExtension }, labeled: segment.labeled, deleted: segment.deleted });