Skip to content

Commit a8ae6aa

Browse files
authored
feat(Searcher): Ignore old data from long running filter responses (#81)
* feat(Searcher): Ignore old data from long running filter responses
1 parent f640e9e commit a8ae6aa

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/core/EntityList.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class EntityList<T> extends StatefulSubject<T[]> {
2525
private readonly $ref: Entity<T>;
2626
private readonly $list: EntityListReference<T>;
2727
protected broker: EntityMessageBroker = EntityMessageBroker.getInstance();
28+
private latestTimestamp = 0;
2829

2930
constructor(type: string, options: EntityListOptions = {}, state?: T[], callingIdentifier = '') {
3031
super(state);
@@ -68,7 +69,14 @@ export class EntityList<T> extends StatefulSubject<T[]> {
6869
this.$list.then((results: BullhornListResponse<T>) => {
6970
this.descriptor = results.meta;
7071
this.$latest = results;
71-
this.next(results.data);
72+
if (!results.timestamp) {
73+
return this.next(results.data);
74+
}
75+
// Ignore responses that are for older requests when we have a newer completed request
76+
if (results.timestamp > this.latestTimestamp) {
77+
this.latestTimestamp = results.timestamp;
78+
this.next(results.data);
79+
}
7280
}, error => {
7381
this.error(error);
7482
});

src/services/QueryService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class QueryService<T> {
9797
}
9898
async run(add: boolean): Promise<BullhornListResponse<T>> {
9999
await this.initialized;
100+
const requestTimestamp = Date.now();
100101
const [response, metadata] = await Promise.all([this.httpGet(this.parameters), this.meta.getFull(this.parameters.fields, this.parameters.layout)]);
101102
const result = response.data;
102103
if (this.shouldPullMoreRecords(result)) {
@@ -112,6 +113,7 @@ export class QueryService<T> {
112113
this.records = result.data;
113114
}
114115
result.meta = metadata;
116+
result.timestamp = requestTimestamp;
115117
return result;
116118
}
117119

src/types/Responses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export interface BullhornListResponse<T> {
8989
data: T[];
9090
messages?: BullhornMessage[];
9191
meta?: BullhornMetaResponse;
92+
timestamp?: number;
9293
}
9394

9495
export interface BullhornEntityResponse<T> {

0 commit comments

Comments
 (0)