Skip to content

Commit

Permalink
[REM] UUID: remove fast strategy
Browse files Browse the repository at this point in the history
THe fast strategy for uuid generator was introduced to speed up the
startup of a model, specifically when generating cells which could be
numerous and the calls to crypto could become a hassle.
However, we realised later on that a uuid was useless for that specific
purpose. More specifically, a uuid is useful to generate unique
identifiers that will be shared accross users to avoid collisions in
multi-user context (i.e. concurrent updates).
In other cases, shortcutting the uuid generator to become a simple
incremented integer value is either wrong or shows the uselessness of
calling uuidGenerator in the first place.

Task: 4216816
Part-of: #5030
Signed-off-by: Vincent Schippefilt (vsc) <[email protected]>
  • Loading branch information
rrahir committed Oct 7, 2024
1 parent 658e1d1 commit 703f2a4
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
15 changes: 2 additions & 13 deletions src/helpers/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,9 @@
* */

export class UuidGenerator {
private isFastIdStrategy = false;

private fastIdStart = 0;

setIsFastStrategy(isFast: boolean) {
this.isFastIdStrategy = isFast;
}

uuidv4(): string {
if (this.isFastIdStrategy) {
this.fastIdStart++;
return String(this.fastIdStart);
//@ts-ignore
} else if (window.crypto && window.crypto.getRandomValues) {
//@ts-ignore
if (window.crypto && window.crypto.getRandomValues) {
//@ts-ignore
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, (c) =>
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16)
Expand Down
1 change: 0 additions & 1 deletion src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export class Model extends EventBus<any> implements CommandDispatcher {
this.handlers.push(plugin);
this.uiHandlers.push(plugin);
}
this.uuidGenerator.setIsFastStrategy(false);

// starting plugins
this.dispatch("START");
Expand Down
2 changes: 0 additions & 2 deletions tests/__mocks__/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
export class UuidGenerator {
private nextId = 1;

setIsFastStrategy(isFast: boolean) {}

uuidv4(): string {
return String(this.nextId++);
}
Expand Down

0 comments on commit 703f2a4

Please sign in to comment.