Skip to content

Commit

Permalink
Remove extra api calls when changing time range
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantinos Sideris committed Mar 1, 2021
1 parent 785d3e0 commit d045852
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
5 changes: 2 additions & 3 deletions dashboard/src/components/overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ const OverviewComponent = {
document.querySelector("#autoComplete").blur();
document.querySelector("#autoComplete").value = `#${tagSelected}`;

State.fetchStats(tagSelected)
State.fetchStats(tagSelected);
}
});
},
Expand Down Expand Up @@ -593,7 +593,6 @@ const OverviewComponent = {
onSelect: (d1, d2) => {
if (TimeRange.setDays(d1, d2))
State.fetchItems(
null,
d1.toISOString(),
d2.toISOString()
);
Expand Down Expand Up @@ -628,7 +627,7 @@ const OverviewComponent = {
};

export default {
oninit: State.fetchItems,
oninit: State.initialize,
oncreate: () => {
// Silent refresh.
State.interval = setInterval(auth.checkInterval, 60000);
Expand Down
28 changes: 21 additions & 7 deletions dashboard/src/models/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ const Model = {
})
.catch(err => auth.retryCall(err, () => Model.fetchStats(tag)));
},
// Fetch the statistics.
fetchItems: (cb, d1, d2) => {
initialize: () => {
Promise.all([
api.getStats({
start: d1 || TimeRange.start().toISOString(),
end: d2 || TimeRange.end().toISOString(),
start: TimeRange.start().toISOString(),
end: TimeRange.end().toISOString(),
timeLimit: TimeRange.timeLimit
}),
api.getTimeline({
Expand All @@ -76,10 +75,25 @@ const Model = {

Model.timeline = values[1];
Model.tags = values[2].tags;

typeof cb === "function" && cb();
})
.catch(err => auth.retryCall(err, () => Model.fetchItems(cb)));
.catch(err => auth.retryCall(err, () => Model.initialize()));
},
// Fetch the statistics.
fetchItems: (d1, d2) => {
api
.getStats({
start: d1 || TimeRange.start().toISOString(),
end: d2 || TimeRange.end().toISOString(),
timeLimit: TimeRange.timeLimit
})
.then(function (obj) {
Model.obj = obj;
Model.dates = utils.getDaysBetween(
new Date(Model.obj.startDate),
new Date(Model.obj.endDate)
);
})
.catch(err => auth.retryCall(err, () => Model.fetchItems()));
}
};

Expand Down

0 comments on commit d045852

Please sign in to comment.