From a8ae6aacff9b162f2d1008af349d4ffe03c473ba Mon Sep 17 00:00:00 2001 From: Nathan Dickerson Date: Thu, 5 May 2022 10:31:31 -0500 Subject: [PATCH] feat(Searcher): Ignore old data from long running filter responses (#81) * feat(Searcher): Ignore old data from long running filter responses --- src/core/EntityList.ts | 10 +++++++++- src/services/QueryService.ts | 2 ++ src/types/Responses.ts | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/EntityList.ts b/src/core/EntityList.ts index a3f74ed..5440782 100644 --- a/src/core/EntityList.ts +++ b/src/core/EntityList.ts @@ -25,6 +25,7 @@ export class EntityList extends StatefulSubject { private readonly $ref: Entity; private readonly $list: EntityListReference; protected broker: EntityMessageBroker = EntityMessageBroker.getInstance(); + private latestTimestamp = 0; constructor(type: string, options: EntityListOptions = {}, state?: T[], callingIdentifier = '') { super(state); @@ -68,7 +69,14 @@ export class EntityList extends StatefulSubject { this.$list.then((results: BullhornListResponse) => { this.descriptor = results.meta; this.$latest = results; - this.next(results.data); + if (!results.timestamp) { + return this.next(results.data); + } + // Ignore responses that are for older requests when we have a newer completed request + if (results.timestamp > this.latestTimestamp) { + this.latestTimestamp = results.timestamp; + this.next(results.data); + } }, error => { this.error(error); }); diff --git a/src/services/QueryService.ts b/src/services/QueryService.ts index db392b2..90a4ffa 100644 --- a/src/services/QueryService.ts +++ b/src/services/QueryService.ts @@ -97,6 +97,7 @@ export class QueryService { } async run(add: boolean): Promise> { await this.initialized; + const requestTimestamp = Date.now(); const [response, metadata] = await Promise.all([this.httpGet(this.parameters), this.meta.getFull(this.parameters.fields, this.parameters.layout)]); const result = response.data; if (this.shouldPullMoreRecords(result)) { @@ -112,6 +113,7 @@ export class QueryService { this.records = result.data; } result.meta = metadata; + result.timestamp = requestTimestamp; return result; } diff --git a/src/types/Responses.ts b/src/types/Responses.ts index b18d9d6..e2ed9d3 100644 --- a/src/types/Responses.ts +++ b/src/types/Responses.ts @@ -89,6 +89,7 @@ export interface BullhornListResponse { data: T[]; messages?: BullhornMessage[]; meta?: BullhornMetaResponse; + timestamp?: number; } export interface BullhornEntityResponse {