Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions js/adapt-contrib-scoring.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ class Scoring extends Backbone.Controller {
* @fires Adapt#scoring:update
*/
update() {
const updateSubsets = !this._queuedChanges?.length
const queuedChanges = [...new Set(this._queuedChanges)];
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to check if the queue already contains the model before adding, rather than removing duplicates later?

Copy link
Copy Markdown
Member

@oliverfoster oliverfoster Jul 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes no difference with arrays at this size.

It is difficult to quantify which is more performant.

It may be cheaper to remove duplicates as the list grows, as at each addition, there would be fewer duplicate comparisons and the list would remain as short as possible. However, the overhead of performing a duplicate comparison each time may cost more than performing a single duplicate check on a larger set later.

It entirely depends on the quantity of duplicate and non-duplicate items, and the frequency of additions. Then, whether it is more important to add quickly and process slowly or vice-versa, or if RAM usage is important than processing speed. etc

const updateSubsets = !queuedChanges?.length
? this.subsets
: this._queuedChanges.reduce((updateSubsets, model) => updateSubsets.concat(getSubsetsByModelId(model?.get('_id'))), []);
: [...new Set(queuedChanges.reduce((subsets, model) => subsets.concat(getSubsetsByModelId(model?.get('_id'))), []))];
updateSubsets.forEach(set => set.update());
this._queuedChanges = [];
if (!updateSubsets.length) return;
Expand Down
Loading