문제

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?

도움이 되었습니까?

해결책

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".

다른 팁

Choose Option A: If each JSON entry is small, having only the id, not the whole document. This is easy to manage and cleanup.

Choose Option B: If each JSON entry is large. I agree with @Bergi

If I understand correctly it is a question about best architecture.

Since you may have "a lot of different versions", you need a quick lookup for localStorage therefore the option b is better. Because in option a, whenever you want to find a specifiv version of the document, you have to go through all items that their id is abc and then iterate through them (worst case: linear search) trying to find the version you are looking for.

However, using . (dot) as the separator isn't probably the best idea. The separator should be a character that is not used in the version number and file name. I would suggest something like /. So the keys will be like:

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"}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top