Page MenuHomePhabricator

API: Support user managed sort order
Closed, DeclinedPublic5 Estimated Story Points

Description

When editing a collection I should be able to do the following:
return this.postWithToken( 'watch', {

				action: 'editlist',
				id: 3,
				before: 'Foo',
				titles: [ 'Bar' ]

} );

This inserts the title 'Bar' in the collection with id 3 before the title 'Foo' which is in the collection.

  • If 'Foo' is not in the collection OR no before parameter is given it adds the new item to the end of the list and throws a warning
  • If 'Foo' is in the collection, it positions the new member(s) before the item 'Foo'

['X', 'Y', 'Foo'] => ['X', 'Y', 'Bar', 'Foo']
['X', 'Y'] => ['X', 'Y', 'Bar']

When I query the members of this collection, I can specify order: 'manual' which orders the collection by the

   {
				action: 'query',
				generator: 'listpages',
				glsporder: 'manual',
				glspid: 3,
				glsplimit: 50
			};

Event Timeline

API already supports the notion of the item sort order (internally its a float, because that makes it much easier to insert items in the middle of the list)

Jdlrobson renamed this task from Every item in the list is given a number corresponding to its position in the list (ascending) to API: Support user managed sort order.Apr 21 2015, 10:38 PM
Jdlrobson assigned this task to Yurik.
Jdlrobson updated the task description. (Show Details)
Jdlrobson set Security to None.
Jdlrobson edited a custom field.
Jdlrobson moved this task from Some day to Should haves on the Gather board.
Jdlrobson updated the task description. (Show Details)

@Tgr, also, take a look at how ordering is implemented in other api modules
(usually using "dir" param)

API already supports the notion of the item sort order (internally its a float, because that makes it much easier to insert items in the middle of the list)

The drawback is that manual ordering might break due to limited float precision. If insertion is done via order = ( prev + next ) / 2, then (given that MySQL float uses 23 bits for the fraction) order might get swapped after 23 rearrangement actions in the worst case (e.g. user repeatedly moving new items to the second position). I guess that's rare enough to ignore.

@Tgr, it is very easy to catch those, and if the difference between prev and next becomes less than some min value, update can simply change sorting value for a few more row. Not a big deal.

I'm not sure it's worth implementing both kinds of updates. If we implement a method to update gli_order for all rows, we can just use that all the time, adding another kind of insertion logic is just unnecessary complication.

I didn't say you should update all rows - you simply update a few surrounding rows, without the whole list, in the worst case. This is about efficiency - updating 5000 pages in someones list just because they decided to move a page into the beginning of the list is not acceptable perf wise - not only would you update the database for 5000 rows, you would also cause replication for all slave DB servers. Not good :)

How would you identify the rows which need updating? Seems hard to do without failing in some edge cases (not that that's necessarily a big problem).

Jdlrobson moved this task from In Analysis to Ready for dev on the Gather Sprint Help! board.
Jdlrobson moved this task from Ready for dev to In Analysis on the Gather Sprint Help! board.
MBinder_WMF subscribed.

This task was declined as part of a batch-decline related to sunsetting the Gather project. Please ping (politely) if this task should be reopened. For more information, you can also see here: https://www.mediawiki.org/wiki/Extension:Gather