b310-digital / teammapper

Mindmapping made simple: Host and create your own mindmaps. Share your mindmap sessions with your team and collaborate on mindmaps.
https://teammapper.org
MIT License
256 stars 21 forks source link

chore: add locking mechanism for backend to prevent sync conflicts on map import #455

Open JannikStreek opened 2 months ago

JannikStreek commented 2 months ago

Description On our servers there are some maps which do not contain any nodes. That can't really be. The only reason which comes to my mind is a failed json import (meaning: someone imported a json file on the server, but during the import an error occurred. As we clean the map first, an empty map would be the result). I think we delete all nodes before adding the new nodes. If the import fails. the map might end up with zero nodes. Best case would be a transaction which is rolled back or something similar.

  // updates map nodes
  async updateMap(clientMap: IMmpClientMap): Promise<MmpMap | null> {
    // remove existing nodes, otherwise we will end up with multiple roots
    await this.nodesRepository.delete({ nodeMapId: clientMap.uuid })
    // Add new nodes from given map
    await this.addNodesFromClient(clientMap.uuid, clientMap.data)
    // reload map
    return this.findMap(clientMap.uuid)
  }

Originally posted by @JannikStreek in https://github.com/b310-digital/teammapper/issues/296#issuecomment-2346110509

Proposed solution There are multiple aspects within this issue and we can split them up in different merge requests:

JannikStreek commented 2 months ago

I would propose the following: