Skip to content
This repository was archived by the owner on May 13, 2024. It is now read-only.

Commit 066d2a8

Browse files
committed
fix(tracking-service): replace drop task modifier
The dropTask modifier prevent multiple instance in the timesheet overview from fetching their data for the task selection dropdown. With the renewed logic, it will prevent fetching the same query multiple times.
1 parent 44b0a21 commit 066d2a8

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

app/components/report-row/component.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
/**
2-
* @module timed
3-
* @submodule timed-components
4-
* @public
5-
*/
6-
71
import { action } from "@ember/object";
82
import { inject as service } from "@ember/service";
93
import Component from "@glimmer/component";
10-
import { tracked } from "@glimmer/tracking";
114
import ReportValidations from "timed/validations/report";
125

13-
/**
14-
* Component for the editable report row
15-
*
16-
* @class ReportRowComponent
17-
* @extends Ember.Component
18-
* @public
19-
*/
206
export default class ReportRowComponent extends Component {
217
@service abilities;
228

239
ReportValidations = ReportValidations;
2410

25-
@tracked task;
26-
2711
get editable() {
2812
return this.abilities.can("edit report", this.args.report);
2913
}

app/services/tracking.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,22 @@ export default class TrackingService extends Service {
288288
* @param {Number} customer The customer id to filter by
289289
* @public
290290
*/
291-
@dropTask
291+
@task
292292
*projects(customer) {
293293
if (!customer) {
294294
// We can't test this because the UI prevents it
295295
throw new Error("No customer selected");
296296
}
297297

298+
const original = this.filterDuplicateTasks(this.projects, customer);
299+
if (original) {
300+
return yield original;
301+
}
302+
303+
// Give it 100ms to "collect" similar requests and
304+
// increases the efficiency even more.
305+
yield timeout(100);
306+
298307
return yield this.store.query("project", { customer });
299308
}
300309

@@ -305,13 +314,38 @@ export default class TrackingService extends Service {
305314
* @param {Number} project The project id to filter by
306315
* @public
307316
*/
308-
@dropTask
317+
@task
309318
*tasks(project) {
310319
if (!project) {
311320
// We can't test this because the UI prevents it
312321
throw new Error("No project selected");
313322
}
314323

324+
const original = this.filterDuplicateTasks(this.tasks, project);
325+
if (original) {
326+
return yield original;
327+
}
328+
329+
// Give it 100ms to "collect" similar requests and
330+
// increases the efficiency even more.
331+
yield timeout(100);
332+
315333
return yield this.store.query("task", { project });
316334
}
335+
336+
/**
337+
* Filters running tasks with the same arguments and returns the first
338+
* task with matching arguments if there is more than one concurrent
339+
* instance of it. Otherwise returns undefined.
340+
*/
341+
filterDuplicateTasks(task, argument) {
342+
const taskInstances = task.scheduler.taskInstances;
343+
if (
344+
taskInstances.length > 1 &&
345+
taskInstances.filter((task) => task.args[0] === argument).length > 1
346+
) {
347+
/* istanbul ignore next */
348+
return taskInstances.find((task) => task.args[0] === argument);
349+
}
350+
}
317351
}

0 commit comments

Comments
 (0)