Page MenuHomePhabricator

Support custom fields in "Order By" for Maniphest
ClosedPublic

Authored by hach-que on Aug 1 2014, 3:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Dec 12, 9:51 PM
Unknown Object (File)
Thu, Dec 12, 7:10 AM
Unknown Object (File)
Tue, Dec 10, 9:20 PM
Unknown Object (File)
Fri, Dec 6, 2:32 PM
Unknown Object (File)
Fri, Dec 6, 2:32 PM
Unknown Object (File)
Thu, Dec 5, 8:16 PM
Unknown Object (File)
Wed, Dec 4, 4:00 PM
Unknown Object (File)
Sat, Nov 30, 1:16 PM
Tokens
"Yellow Medal" token, awarded by btrahan."Doubloon" token, awarded by epriestley.

Details

Summary

Resolves T4659. This implements support for sorting tasks by custom fields.

Some of this feels hacky in the way it's hooked up to the Maniphest search engine and task query.

Test Plan

Queryed on a custom date field, with a small page size, and moved back and forth through the result set.

Diff Detail

Repository
rP Phabricator
Branch
arcpatch-D10106
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 1995
Build 1996: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

hach-que retitled this revision from to Support custom fields in "Order By" for Maniphest.
hach-que updated this object.
hach-que edited the test plan for this revision. (Show Details)
hach-que added a reviewer: epriestley.
src/applications/maniphest/query/ManiphestTaskQuery.php
582–586

I wanted to make this more general, but different queries have different table aliases, and the underlying class only knows about the aliases of JOINs it does for application search, not the primary object's table alias.

epriestley edited edge metadata.

This is awesome! I think I caught one real issue (incorrect construction of ORDER BY clause in the presence of a "Group by" selection in the UI). Some general rambling elsewhere, but all of that seems really nitpicky and easy to change later if we hit real issues. I think it largely does a good job of balancing complexity with making the feature work, since we don't need any of the full-power generalizations yet.

src/applications/maniphest/query/ManiphestTaskQuery.php
582–586

I think this is reasonable as-is, especially for the first implementation.

I think it needs to get built later down, though. Otherwise, we're dropping the order constraints added by $this->groupBy. Specifically, "group by X, order by custom field Y" in the UI should produce an "ORDER BY x, y" clause. By returning early, we'll just get an "ORDER BY y" clause. I would expect the UI to show the wrong results if a "Group by:" is selected.

src/applications/search/engine/PhabricatorApplicationSearchEngine.php
772

I think this logic is OK for now, but it does mean non-configured custom fields can't provide orderings. For example, "Title" in Differential is a custom field, but can't generate a meaningful result for buildOrderIndex().

If some of this logic was on the Field and the call looked more like:

$field->applyApplicationSearchOrderToQuery($this, $query)

...(similar to applyApplicationSearchConstraintToQuery()), that would let fields like "Title" implement the method as $query->setOrderBy(SOME_TITLE_CONSTANT) while custom fields could call $query->withApplicationSearchOrder(...).

This is an easy generalization to make later, though.

817

I wonder if we should make this separately configurable (e.g., add a new sort or order key to field configuration, which activates it in this UI). For now, I think it's fine as-is -- it's all in a dropdown anyway.

src/infrastructure/customfield/field/PhabricatorCustomField.php
641

This feels a little bit awkward, but I think it's OK until we have a clearer picture of things. (Some inlines elsewhere flesh this out more.)

src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
366–367

Docs disagree with actual parameters.

625

At some point, although not necessarily yet, I think this should probably be something like $field->buildOrderIndex()->getIndexValue(). In particular, you could imagine a field which stores a different value than it indexes. This would require buildOrderIndex() to sometimes return a populated index and sometimes return a placeholder object, though. I don't really see a way to structure this elegantly offhand. I think this is fine for now, but we'll probably tweak it in the future.

This revision now requires changes to proceed.Aug 1 2014, 5:02 PM
hach-que edited edge metadata.

Fix up ordering when "Group By" is present

I'm going to hold off doing any generalisations or major refactorings. I think the Order By behaviour probably needs to be generalised (including the "built-in" order bys). While we're at it, generalising Group By would probably be good as well, by moving a lot of that query construction into PhabricatorCursorPagedPolicyAwareQuery.

Moving this kind of logic into the base class would vastly simplify the ManiphestTaskQuery implementation, would allow other queries to take advantage of it and would probably make a bunch of this "if custom field ordering, ignore switch statement" kind of logic go away.

hach-que edited edge metadata.

Replace array_push with index operator.

epriestley edited edge metadata.

Yeah, that seems reasonable to me. This looks good, thanks!

This revision is now accepted and ready to land.Aug 2 2014, 6:06 AM
hach-que updated this revision to Diff 24339.

Closed by commit rP46b4fa85d097 (authored by @hach-que).

This comment was removed by pyleaf.