javascriptversion-controllocal-storagerevisions

Should I store multiple versions of a document in localstorage by document_id or document_id_version?


I need to write a script to manage conflicting versions of a document in local storage. I'm currently thinking about two alternatives and have trouble deciding which one will be more scalable.

My documents will be stored as JSON and will have an id and a revision to identify the version.

Currently I'm creating a path in localstorage like so:

PATH/TO/DOCUMENT/id

At this path the document is stored as JSON

{"id":"abc","version":"1-a","content":"foo"}

I'm using POST,PUT(update),GET and REMOVE. POST/PUT require id and version while GET/REMOVE only require id.

To allow for conflicting versions to exist in local storage I'm not sure whether to

a) store at existing path and add version as 2nd JSON string like so:

PATH/TO/DOCUMENT/id   {"id":"abc","version":"1-a","content":"foo"},
                      {"id":"abc","version":"2-b","content":"foodforthought"}

b) store at path.id and keep a "single files"

PATH/TO/DOCUMENT/id.1-a   {"id":"abc","version":"1-a","content":"foo"}
PATH/TO/DOCUMENT/id.2-b   {"id":"abc","version":"2-b","content":"foodforthought"}

Question:
Which one makes more sense in terms of scalability and a lot of different versions to exist?


Solution

  • Which one makes more sense in terms of scalability and a lot of different versions to exist?

    Option B. Here you can read / write single document versions without loading the whole JSON string (and then object, when it comes to manipulation) into the memory. Especially when it comes to many and huge documents, this will save you some time.

    However, if you have lots of versions of one huge document that do not differ much from each other, it might be better in terms of performance and memory-usage to store them with incremental or differential versioning, which would make more sense in one single "JSON file".