sixthedge / opentbl

5 stars 2 forks source link

[RAT Builder] Question IDs could collide. #29

Closed jamesfid closed 7 years ago

jamesfid commented 7 years ago

The way that the system is generating the id of a new question could have an issue. It runs this function:

  get_next_id: (type) ->
    items = @get_items(type).sortBy('id')
    id    = items.get('lastObject.id')
    if ember.isPresent(id) then id = id + 1 else id = 1

Unlikely to happen, but this is possible:

@DylanBell Should we consider somethign like UUID or keeping track in the JSON of the last used or something?

DylanBell commented 7 years ago

@jamesfid currently the id is used for lookups, but nothing beyond that. I think we'd be well-served using a UUID. I found a few snippets for generating them on stackoverflow (http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript), and am gonna try tossing that code into a mixin.

DylanBell commented 7 years ago

There's also a couple of npm modules that do it..but given the outside chance of a collision use-case currently, I think the Math.random() approach should be sufficient.

DylanBell commented 7 years ago

Resolved by creating a helpers/common/uuid.coffee mixin, which contains a function to return a (reportedly) RFC4122 version 4 compliant UUID! (in commit f5ffbc8