Skip to content

Commit

Permalink
feat(Searcher): Ignore old data from long running filter responses (#81)
Browse files Browse the repository at this point in the history
* feat(Searcher): Ignore old data from long running filter responses
  • Loading branch information
ndickerson authored May 5, 2022
1 parent f640e9e commit a8ae6aa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/core/EntityList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class EntityList<T> extends StatefulSubject<T[]> {
private readonly $ref: Entity<T>;
private readonly $list: EntityListReference<T>;
protected broker: EntityMessageBroker = EntityMessageBroker.getInstance();
private latestTimestamp = 0;

constructor(type: string, options: EntityListOptions = {}, state?: T[], callingIdentifier = '') {
super(state);
Expand Down Expand Up @@ -68,7 +69,14 @@ export class EntityList<T> extends StatefulSubject<T[]> {
this.$list.then((results: BullhornListResponse<T>) => {
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);
});
Expand Down
2 changes: 2 additions & 0 deletions src/services/QueryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export class QueryService<T> {
}
async run(add: boolean): Promise<BullhornListResponse<T>> {
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)) {
Expand All @@ -112,6 +113,7 @@ export class QueryService<T> {
this.records = result.data;
}
result.meta = metadata;
result.timestamp = requestTimestamp;
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/types/Responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface BullhornListResponse<T> {
data: T[];
messages?: BullhornMessage[];
meta?: BullhornMetaResponse;
timestamp?: number;
}

export interface BullhornEntityResponse<T> {
Expand Down

0 comments on commit a8ae6aa

Please sign in to comment.