0

I'm having a series of data as documents in a document db (CouchDB)

Sample of a document looks like below

{
 _id: xxx
 _rev: xxx
 data: xxx
 position: 1
}

These documents displays in a web front-end in a vertically scrollable list and any item can be dragged and dropped to change position.

The position key is always unique and programmatically using it to sort and manage the "drag and drop" feature. In a drag and drop, dragged item's (document's) position updates to the new position along with the all the other documents which got higher position number than the dragged document's position.

As an example: in a 1000 item list, if 6th item dragged to 2nd place, all the 3 to 1000 documents should be updated with the new position

With the current system, we use couchDB update handler to update each document to it's new position.

With few thousand documents, its taking less time to update all the documents to newer position. However the number of docs can be few hundred thousand in future.

Is there a better way of handling a "drag n drop" other than recording and maintaining the position.

inckka
  • 129
  • 5
  • 1
    If the position key is used for sorting but not for absolute positioning, you can simply use fractional positions. To move the 6th item to second place, you just change its position from 6 to 1.5. After a number of moves, a renumbering may be necessary to get equal spacing, but that would be relatively rare. – Hans-Martin Mosner Jun 25 '20 at 22:31
  • The other aspect is that manual ordering of 1,000 items is questionable, doing it on a list of 100,000 items is absolutely ridiculous. You just don't want to do this. – Hans-Martin Mosner Jun 26 '20 at 10:14

0 Answers0