From d07dd098e7812c5f27f966fb013050ef6783cab6 Mon Sep 17 00:00:00 2001 From: rozetko Date: Wed, 15 May 2019 01:53:31 +0300 Subject: [PATCH] Remove old detected segments and detection spans when learning starts #650 (#651) --- server/src/controllers/analytics_controller.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/src/controllers/analytics_controller.ts b/server/src/controllers/analytics_controller.ts index 50380c2..e19e25b 100644 --- a/server/src/controllers/analytics_controller.ts +++ b/server/src/controllers/analytics_controller.ts @@ -206,7 +206,10 @@ export async function runLearning(id: AnalyticUnit.AnalyticUnitId, from?: number if(analyticUnit.status === AnalyticUnit.AnalyticUnitStatus.LEARNING) { throw new Error('Can`t start learning when it`s already started [' + id + ']'); } - + const oldSegments = await Segment.findMany(id, { labeled: false, deleted: false }); + // TODO: segments and spans are coupled. So their removing should be a transaction + await Segment.removeSegments(oldSegments.map(segment => segment.id)); + await Detection.clearSpans(id); let oldCache = await AnalyticUnitCache.findById(id); if(oldCache !== null) { oldCache = oldCache.data;