I am currently working on an Android app where users can order their list via drag and drop in any order they want. Therefore, I must store the sort order in a variable in a column. I was thinking of giving each row a number like 100000, 200000, 300000, etc and if a user moves an item between 100000 and 200000, then its sort number becomes the average of its neighbours ie 150000. This way, I only have to update the single row's sort number as opposed to every row in the table if I did a normal i+1 sort value.
What is the most efficient? Do large numbers use more resources or take longer to sort? I only expect <100 rows so if large numbers take longer to sort, I might be better off using smaller numbers and "resetting" more often. I know with so few rows, it wouldn't really matter if I just did a i+1 sort method and update every row in my db every time. But I am also syncing my SQLite data with a BAAS and most of them do not allow batch saving. So for every row I modify, I have to make 1 API request. That is why I am trying to minimize the amount of rows I modify when I reorder an item.
Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire