Problem/Motivation
(Not sure which issue queue to file this under, so starting here.)
"Usability" is an "official" topical tag we use in the Drupal core queue to track usability-related issues. However, you'd never know it from typing it into the issue tags box:

Both the lack of transparency around the core tags, as well as the propensity of typos to enter the vernacular make this a pretty big barrier to contribution.
It could be solved by sorting the list instead of by... I don't even know how that's sorted :) maybe alphabetically? ... sorting it by the count of issues (ideally within the current project) that are tagged with that term.
This would put "Usability" straight at the top of the list, possibly followed by "Needs usability review", etc. making it super easy to select the proper choice, and pushing one-off tags to the bottom where they're less likely to be mistakenly chosen.
FWIW, I believe this problem is also part of why CORE-SA-2014-05 wasn't caught sooner. Note that in #2146839: Database ExpandArguments placeholder naming issues when using array the reporter chose to create "#security" as the tag (you can confirm this because https://www.drupal.org/project/issues/search?issue_tags=%23security only shows that issue tagged). Most likely this is because the list of tags that comes up when you enter "security" looks like this, none of which are remotely right:

The ones people actually do look at are ones like Security (100+ issues), Security Advisory Follow-Up (50+ issues), etc. Had those been at the top of the list, they surely would've been selected, rather than a new tag invented.
Proposed resolution
Remaining tasks
To work on the d.o server
server: tags-drupal.redesign.devdrupal.org
get access: username: drupal password: drupal
to be able to edit a issue (see the autocomplete tag): username: bacon password bacon
sample issue: https://tags-drupal.redesign.devdrupal.org/node/2380883
Handbook page for working on d.o: Develop on our server (preferred) https://www.drupal.org/node/1018084
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #92 | Screen Shot 2015-03-11 at 10.15.35 AM.png | 38.42 KB | webchick |
| #87 | sort_autocomplete_of-2362065-87.patch | 6.76 KB | yesct |
| #87 | sort_autocomplete_of-2362065-87-testsonly.patch | 5 KB | yesct |
| #87 | interdiff.2362065.85.75.txt | 4.74 KB | yesct |
| #85 | sort_autocomplete_of_2362065-85.patch | 7.85 KB | bkosborne |
Comments
Comment #1
webchickI believe this is coming from core: http://cgit.drupalcode.org/drupal/tree/modules/taxonomy/taxonomy.pages.i... There's no sort on the query that builds the autocomplete list.
I'm not sure how well a patch to change this in D7 core will be received, given D7 has worked the way it's currently working for almost 4 years now. OTOH this seems like a logical way to sort it for default behaviour (assuming it wouldn't bring a site with as many terms as ours down to its knees, which it may well). I'm not too worried about this issue in D8 because most likely we would solve this by using Views to generate the list: #2174633: View output is not used for entityreference options
For Drupal 7, a workaround could be overriding the taxonomy/autocomplete menu callback with Views, and/or a hook_menu_alter() to insert our own query.
Comment #2
drummThe handler used on Drupal.org is from Search API: http://cgit.drupalcode.org/search_api/tree/contrib/search_api_views/incl... That callback looks similar to core's.
Ordering by usage would indeed slow down matches:
Drupal.org has 19,135 issue tags, sorting among that many looks doable, 20k isn't actually that much compared to some of the other things Drupal.org does to the DB. It would be okay for us, still answering queries quickly, maybe with some noticeable latency, a fraction of a second. (Sorting by name has effectively zero performance impact compared to the current query.)
Comment #3
yesct commentedthis would also help what #2013222: Add "Issue tasks" to project issues and correlate tasks with handbook documentation set out to do (in part)
Comment #4
yesct commentedis this a candidate for a "quick easy win" to get on the d.o priorities list of issues?
Comment #5
drummComment #6
joelpittetWould it also help to add in a sort on i.nid (to get a kind of 'last used') in the mix? Some kinda of secondary sort on 'freshness'.
+1 for this issue regardless:)
Comment #7
yesct commentedOne option is to add a configuration option in the views UI settings page admin/structure/views/settings/advanced (defaulting to the current non-sorted by usage order).
and then use that config in https://api.drupal.org/api/views/includes%21ajax.inc/function/views_ajax...
or, project issue tracking module could implement a hook_menu_alter() for
'admin/views/ajax/autocomplete/taxonomy'
'page callback' => 'views_ajax_autocomplete_taxonomy',
to be some other callback function that had the sort we want
Comment #8
Bojhan commentedI think this would be a great first step. I imagine it has some performance impact, but there should also be ways to mitigate that as much as possible?
Definitely hoping this ends up on the short list!
Comment #9
yesct commentedSo, fixing this in drupal 8 core is probably not going to happen if adding sort settings gets categorized as a feature request.
Fixing it in drupal 7 core... would be weird if it can't be fixed in d8 first.
So I think that leaves us with doing a hook menu alter something that is specific to d.o project issue tracking.
Can someone provide some more specific guidance on how to implement this?
Comment #10
joachim commentedThe menu change should be fairly simple:
- use hook_menu() to define a custom path, say, project_issue/autocomplete/TID. Copy taxonomy module's hook_menu() item for that
- for the callback, again, copy what taxonomy module has for its normal autocomplete, adding the sort to the query.
Next problem is getting the form to use this path instead. IIRC taxonomy autocomplete widget does something weird and unlike normal FormAPI autocomplete -- I seem to recall an issue about tidying that up. This may or may not have an impact here ;)
One way might be to use form alteration. A heavier (but maybe simpler alternative) would be to just make a new widget.
That said...
This is the query from taxonomy_autocomplete():
It doesn't get the vocab in its metadata, which is a shame, but it's tagged. So an implementation of hook_query_TAG_alter() could check the t.vid condition for the project issue tags vocab (assuming that's a separate vocab? I don't know) and add the sort order to the query.
That's much less code -- just one function. However, will the alter hook have a performance cost?
Comment #11
drummThe handler used on Drupal.org is from Search API: http://cgit.drupalcode.org/search_api/tree/contrib/search_api_views/incl... That callback looks similar to core's.
Comment #12
xjmI think one alternative solution that might avoid expensive queries is adding exact matches at the top of the list, at least?
Comment #13
yesct commentedI wonder if some js delay like in #2333053: JavaScript for #type => 'machine_name' registers key presses on 'source' slowly later, when label has spaces, special or international characters in it might help here also. (waiting for people to pause while typing before trying to get the results)
Comment #14
he0x410 commentedPer discussion with YesCT in #durpal-contirbute, I will try to come up with custom module according the #10 comment, which might be ported to d.o.
Comment #15
yesct commentedMaybe a d.o dev environment already exists that we can use to test this?
or one might need to be created https://www.drupal.org/node/1018084 "Develop on our server (preferred)"
Comment #16
drummI started the build of tags-drupal.redesign.devdrupal.org for this issue.
Comment #17
he0x410 commentedHi, I'm sorry for delay, didn't have time to look into it last week.
First I was going to modify 'project_issue' module, but it does not have tags field for Issues. "Issue tags" field was created in drupalorg_project, so I have improved this module.
I have added menu item (taxonomy/autocomplete/taxonomy_vocabulary_9) with callback function "drupalorg_project_issue_tag_autocomplete", which is based on "taxonomy_autocomplete".
This menu item affects only taxonomy/autocomplete/taxonomy_vocabulary_9, so other arguments in "taxonomy/autocomplete/%/%" still works with core taxonomy_autocomplete.
Execution times:
- for "Usability" = 0.05158805847168
- for "Needs" =0.031492948532104
Patch is attached.
It is uploaded to tags-drupal.redesign.devdrupal.org, so you can verify how it works.
Comment #18
he0x410 commentedI've just realized, that I had to add "do-not-test" to the patch name - it will fail tests, because the patch is for https://www.drupal.org/project/drupalorg
Comment #19
he0x410 commentedMoving to Drupal.org customizations
Comment #20
Bojhan commentedI am guessing this needs review by drumm.
Comment #21
drummThe handler used on Drupal.org is from Search API: http://cgit.drupalcode.org/search_api/tree/contrib/search_api_views/incl... That callback has a different menu path.
Comment #22
he0x410 commentedHi drumm,
Could you explain more? I don't understand why are you referring to Search API?
thanks
Comment #23
drummSorry, I mixed this up with the autocomplete for the advanced issue queue search. It would be good to update to match, but that doesn't have to be part of this issue.
Comment #24
yesct commentedMade an issue for that other autocomplete
#2398379: Sort autocomplete of issue tags descending by usage count *on advanced search page*
Comment #25
drummThe implementation of this does belong in Project Issue module. Drupalorg currently doesn't do any issue-tags-related customization; and I expect this would be a welcome feature for anyone using Project Issue.
To make the menu alter generic, we need to see which vocabularies are autocomplete issue tags. The algorithm will be something like:
Comment #26
he0x410 commented@drumm
I was going to do it in Project Issue, but that module does not have tags field out of the box. I see, that it was added in drupal.org manually.
I commented this above.
https://www.drupal.org/node/2362065#comment-9390563
Comment #27
yesct commentedIdentifying this as a potential good issue for Sprint Weekend. See discussion at #2407325: preparing for a sprint, would be good to have a list of candidate issues. Adding sprint queue tag.
If this is worked on during the sprint, please add the tag SprintWeekend2015. Add a comment when you start work saying what you are about to do, so we can coordinate.
Comment #28
drummWhile Project Issue doesn't make a tag vocabulary out of the box (maybe it should, that's another issue), it does have the configuration and customization for tag vocabularies. For example,
project_issue_form_taxonomy_form_vocabulary_alter()adds the configuration to edit vocabulary pages. Grepping forproject_issue_taxonomy_vocabulary_issue_queue_shows the various things project issue does for the vocabulary(/ies).See #25 for implementation details for this issue.
Comment #29
damienmckennaFor D7 core, adding an extra "taxonomy_autocomplete" tag could help, because then another module could customize the results.
Comment #30
damienmckennaFYI for core I opened a new issue: #2409171: Add a specific tag to the taxonomy_autocomplete query
Also, there was already an existing issue but it was focused on altering the output: #2069967: Add an alter hook for taxonomy_autocomplete results
Comment #31
develcuy commentedComment #32
develcuy commentedRemoved tag by mistake
Comment #33
ericjenkins commentedI am at a global sprint looking at this issue, along with Alimac. YesCT says I need to request access to the Dev environment located at:
https://tags-drupal.redesign.devdrupal.org/
per the steps listed at: https://www.drupal.org/node/1018084
It looks like the next thing to do is to take Patch #17 and try to make it work on project_issue instead of drupalorg.
Comment #34
ericjenkins commentedI logged into the server: tags-drupal.redesign.devdrupal.org
In /var/www/dev/tags-drupal.redesign.devdrupal.org/htdocs/sites/all/modules/drupalorg, I checked out a new branch titled '2362065-17' and committed all pending changes (included changes for this issue and Critical Block). Then, I checked out branch '7.x-3.x' to emulate site behavior prior to any of these changes.
After this, I cleared caches, entered 'usability' into the Issue Tags field on page: https://tags-drupal.redesign.devdrupal.org/node/2380883
We observed that 'Usability' did not appear at the top of the tag list. In fact, 'Usability' did not appear at all.
Then, I changed directories to /var/www/dev/tags-drupal.redesign.devdrupal.org/htdocs/sites/all/modules/project_issue, I committed existing minor changes to project-issue.info to a new branch titled '2362065-stuff', and then I checked out another new branch titled '2362065-34'.
Then, I pasted both hunks from Patch #17 into the new branch titled '2362065-34'. I adjusted the function callback name to match the new project_issue module.
After this, I cleared caches, entered 'usability' into the Issue Tags field on page: https://tags-drupal.redesign.devdrupal.org/node/2380883
We observed that 'Usability' did appear at the top of the tag list.
The resulting Patch #34 is attached.
I'm done for the day. Next, think about a better name for the callback function project_issue_issue....
Also, see if the performance impact has already been tested. There was some performance related code that was in the drupalorg 2362065-17 branch that I did not carry over to project_issue. Does this still need performance evaluation?
Comment #36
yesct commentedI'm not sure why that wont apply with git. I dont see any reason.
it did apply with patch -p1 (see https://www.drupal.org/patch/apply )
And I make a patch with git diff (which is the same way the previous patch was made...)
Maybe next time we should do a scp instead of copy and paste from the server to a local file.
Comment #37
ericjenkins commentedI thought about the function name 'project_issue_issue_tag_autocomplete', and I think it is fine. I also caught a debugging variable declaration ($time_start) that I originally missed, but now it is out. Re-posting the new patch. I think this is ready to go.
Comment #38
drummtaxonomy_vocabulary_9should not be hard-coded. #25 has some pseudocode for how to know which vocabulary/ies are autocomplete tags for issues.Comment #39
yesct commentedadded info from the comments to the summary about how to work on the issue.
Comment #40
les limWait, we have an "official" topical tag list? /rubs eyes
Could we formalize that list, cache it, and have an ultra-fast autocomplete of preferred tags? It could even be two-step, returning the fast preferred results first and then the deeper search later.
Comment #41
joachim commented> Could we formalize that list, cache it, and have an ultra-fast autocomplete of preferred tags?
Simplest way to do that would be to add a boolean field to the tags taxonomy: yay for D7 and fields on everything! :)
Comment #42
cilefen commentedThis is the menu alter recommendation from #25 only.
Comment #43
cilefen commentedThis should remove the vocabulary hardcoding completely. I haven't tested this yet.
Comment #44
yesct commentedhm.
Comment #45
cilefen commented#43 works after a cache clear. Now we must put in the optimizations mentioned in #40-41.
Comment #46
cilefen commentedLet's get this in and optimize in #2418255: Formalize and optimize autocomplete of issue tags *in the issue metadata form*.
Comment #47
damienmckennaThen it needs a hook_update_N() to clear the appropriate cache.
Comment #49
cilefen commentedI have never used a specific cache clear function. I hope this is the right one for this situation.
Comment #50
yesct commentedlooks good to me, let's see what drumm (or others say if they want to look also)
Comment #52
drummLooks okay, committed.
Comment #53
drummNow deployed.
Comment #54
wim leersSo. Much. Win.
Thank you!
Comment #55
wim leersOops, that tag was from a test that I apparently didn't remove properly. I'm already skewing the numbers :P
Comment #56
wim leersUnfortunately, on many issues, this is somehow causing "9/" to be prefixed to the first tag in the list of tags. I've seen it happen, but so have webchick and Alex Pott. Or at least, this is the most likely suspect.
Comment #57
cilefen commentedIs this on the issue tags list or the autocomplete? Can you give an example?
Comment #58
wim leersOn this very issue, type ", DX" at the end of the issue tags, wait for it to autocomplete, select "DX (Developer Experience)" and BAM, "9/" is prefixed to the list of tags.
Comment #59
cilefen commentedAt least it is self-documenting.
Comment #60
wim leers:D
Comment #61
cilefen commentedI don't know what the point of this prefix is.
Comment #62
wim leersAnother problem that seems to have been introduced by this: some tags don't autocomplete. Like "Contributed project blocker", which is definitely a valid tag: https://www.drupal.org/project/issues/search/drupal?project_issue_follow.... Note that on *that* page, it does autocomplete, just not at
/node/add/project-issue/drupal.Comment #63
cilefen commentedThe test site has the same bug so we could have seen this coming.
Comment #64
wim leersAnd another instance of where the "9/" prefix problem occurred: #2424309: Expose more language container parameters, to allow services to be language-aware efficiently.
Comment #65
cilefen commentedIf anyone has time to work on this in the short-term, the test site is up-to-date with #49 with cleared caches, and does in fact reproduce the problem.
Comment #66
wim leers@jhodgdon also noticed this and filed #2424399: Tag auto-complete field has a problem, which I've just marked as a duplicate.
Comment #67
tim.plunkettI'm guessing the 9 is coming from taxonomy_vocabulary_9 somehow?
Comment #68
webchickOh good, glad it's not just me.
When it seems to occur for me is when I'm adding a new tag to the textfield (like now, because it sounds like we should have tests for this). Upon leaving the Issue tags field, the "9" gets prepended to "Usability," which is the first tag in the list.
Comment #69
drummI'm rolling this back for now: https://bitbucket.org/drupalorg-infrastructure/drupal.org/commits/05c439....
When fixing this, please do not include another
hook_update_N(). For Drupal.org deployments, we have the jobs set up so specific cache clears are a checkbox on deployment, so it isn't necessary to script them.Comment #70
drummThat rollback is deployed now. I'll leave the commits in project_issue as-is, unless another issue in this project wants to be deployed before this is fixed.
Comment #71
cilefen commentedI think I found the bug, it is that
func_get_args()didn't expect the new argument I added. Fixing...Comment #72
cilefen commentedTest manually at https://tags-drupal.redesign.devdrupal.org/node/2380883 bacon/bacon. Needs tests.
Comment #73
webchickAlso needs a comment. :) It's not totally intuitive what that line is doing.
Comment #74
cilefen commentedComment #75
cilefen commentedTo anyone wanting to write the tests, you will need to do the following:
project_issue_taxonomy_vocabulary_issue_queue_1. It is important that thetid of the taxonomy actually is '1'.Comment #76
cilefen commentedThere are some hardcoded assumptions in the patch which is the reason for how 'highly-tuned' it is. I came along after those but we could consider making it a little more flexible.
Comment #77
cilefen commentedThis test is not quite done.
Comment #78
yesct commentedlet's see the test results anyway.
Comment #79
yesct commented@cilefen so what is next here?
[edit]
oh, I guess the @todo's in the patch. :)
Comment #80
cilefen commented@YesCT Exactly. The bug is fixed AFAIK.
Comment #81
bkosborneI'll finish the tests for this over the weekend.
Comment #82
bkosborneTests attached.
However, I this patch still has some hardcoding going on and could use a bit more work.
The original menu route item for taxonomy autocomplete looks like this:
The real path to get results for something like this would be a request to
/taxonomy/autocomplete/[field_name]/[terms]The patch that was committed does this in a menu alter:
This does not look right to me. Instead of replacing the menu route from the taxonomy module, we're adding one that's more "specific", but we're relying on the field name to start with
taxonomy_vocabulary_. Maybe on d.o. thats how the field name exists, but not every site using the Project Issue module.I think we should instead just completely override the original menu route from taxonomy module with our own. Inside it, we loop through each taxonomy that's part of that field and check if that taxonomy has the special variable
project_issue_taxonomy_vocabulary_issue_queue_[vid]set from this module. If so, then we alter the query to take usage into account.Can someone back me on that? If so I'll work on it.
Comment #83
bkosborneComment #85
bkosborneDisregard last patch (interdiff still valid tho)
Comment #86
cilefen commentedI agree 100%. But unless you or I can make those changes early this week, should we hold off improvements for a follow-up? It works now so if we can get basic tests passing, it will be good for upcoming sprints. @YesCT - thoughts?
Comment #87
yesct commentedthis change does not seem related to this issue.
line wrapping off on this. I'll fix it.
Also.. I think we should be able to show that the added tests would have caught the problem.
Hoping that this tests only patch shows that and fails.
Comment #89
drummLooks okay, committing.
Comment #91
drummNow deployed.
Comment #92
webchickYEAHHHH!! Thanks so much for the work on this, everyone! This is a HUGE "contributor experience" improvement. :)
Comment #93
yesct commentedwow!
Comment #94
yesct commentedsomething I didn't notice before, but seems fine, is that usage is per project. For example, in Core, usability is high, but in this queue it is not.
Comment #95
yesct commentedopps.
Comment #96
webchickYeah, I think that's desired behaviour. Sucks for things like "Usability" that make sense in basically every project, but then one could argue those should maybe be default components instead of tags.
Comment #97
wim leersSo. Much. Win.
Thanks!
Comment #98
yesct commentedWe should now do the same thing on the advanced search tag field
#2398379: Sort autocomplete of issue tags descending by usage count *on advanced search page*
Comment #99
cilefen commented@bkosborne Regarding #82, should we handle that in a new follow-up or in #2418255: Formalize and optimize autocomplete of issue tags *in the issue metadata form*?