phlask-map icon indicating copy to clipboard operation
phlask-map copied to clipboard

[V2] Fix concurrency concerns for resource submission

Open vontell opened this issue 10 months ago • 0 comments

When submitting a new resource using our submission form, there is a potential issue with conflicts within our firebase database. More specifically, take a look at these two lines of code

const database = getDatabase(dbConnection);
set(ref(database, '/' + (values.count + 1).toString()), newData);

values.count here is a count of the entries in the firebase database, which is fetched when this component is mounted. However, if two users submit a resource at the same time or around the same time, they will write the resource to the same index. There are two ways we might be able to address this:

  • Instead of an index, we should just use a UUID or unique identifier for resources
  • Find some Firebase reference or code for doing and update vs a set on the firebase database - they may have support for automatically calculating this index.

Desired behavior: When two users submit a resource at the same time, they both exist in the table.

vontell avatar Apr 17 '24 11:04 vontell