Skip to content

Commit

Permalink
Merge pull request #1072 from wazuh/fix-duplicate-results-tables
Browse files Browse the repository at this point in the history
Avoid fetching twice the same data
  • Loading branch information
Jesús Ángel committed Dec 10, 2018
2 parents bfc3f65 + 33f1f00 commit 73b0a7f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion public/services/data-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class DataFactory {
this.sortValue = false;
this.sortDir = false;
this.sortValue = false;
this.busy = false;
if (this.implicitFilter) this.filters.push(...this.implicitFilter);
}

Expand Down Expand Up @@ -56,6 +57,8 @@ export class DataFactory {

async fetch(options = {}) {
try {
if(this.busy) return { items: this.items, time: 0 };
this.busy = true;
const start = new Date();

// If offset is not given, it means we need to start again
Expand Down Expand Up @@ -89,9 +92,10 @@ export class DataFactory {

const end = new Date();
const elapsed = (end - start) / 1000;

this.busy = false;
return { items: this.items, time: elapsed };
} catch (error) {
this.busy = false;
return Promise.reject(error);
}
}
Expand Down

0 comments on commit 73b0a7f

Please sign in to comment.