How to save a particular, mutable “order” into a database

后端 未结 9 921
北恋
北恋 2021-02-05 03:34

Suppose I have some objects, and I want the user to be able to reorder them in any way they wish, say, by dragging them around. So I\'d have

  • Cheese
  • Muffin
9条回答
  •  太阳男子
    2021-02-05 04:26

    In my applications read operations are going to happen much more frequently than writes. Go with the numerical value to indicate sort order and deal with the cost of reordering the items. This is more than made up for by the fact that you can efficiently retrieve the items in the correct order for display purposes (which in a typical application happens more frequently than resorting does).

    Also, as already mentioned, if you retrieve a subset of the data (filter on type or something) the remaining items are still in the proper sort order.

    Remember the mantra K.I.S.S.

提交回复
热议问题