Browse Source

Old segments are not deleted #198 (#204)

fix Old segments are not deleted #198
pull/1/head
Evgeny Smyshlyaev 6 years ago committed by GitHub
parent
commit
c3ca05f1f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      server/src/controllers/analytics_controller.ts
  2. 8
      server/src/models/segment_model.ts

4
server/src/controllers/analytics_controller.ts

@ -190,6 +190,10 @@ export async function runPredict(id: AnalyticUnit.AnalyticUnitId) {
// } // }
// } // }
let lastPredictedSegments = await Segment.findMany(id, { labeled: false, deleted: false });
let segmentsToRemove = lastPredictedSegments.filter(s => payload.segments.indexOf(s) === -1);
Segment.removeSegments(segmentsToRemove.map(s => s.id));
Segment.insertSegments(payload.segments); Segment.insertSegments(payload.segments);
AnalyticUnitCache.setData(id, payload.cache); AnalyticUnitCache.setData(id, payload.cache);
AnalyticUnit.setPredictionTime(id, payload.lastPredictionTime); AnalyticUnit.setPredictionTime(id, payload.lastPredictionTime);

8
server/src/models/segment_model.ts

@ -56,6 +56,14 @@ export class Segment {
obj.labeled, obj.deleted, obj._id obj.labeled, obj.deleted, obj._id
); );
} }
public equals(obj: Segment) : boolean {
return this.analyticUnitId === obj.analyticUnitId &&
this.from === obj.from &&
this.to === obj.to &&
this.labeled === this.labeled &&
this.deleted === this.deleted;
}
} }
export type FindManyQuery = { export type FindManyQuery = {

Loading…
Cancel
Save