Similar to #1616962: Replace $node->title with $node->label(), let's make use of the label() method of terms when linking to it.
In conjunction with #1616952: Add a langcode parameter to EntityInterface::label(), this is going to help make the term name appear properly translated. Also it brings in possible alterability of it via changing the label key/property.
Comment | File | Size | Author |
---|---|---|---|
#62 | taxonomy-term-label-1616972-62.patch | 17.64 KB | Schnitzel |
#56 | taxonomy-term-label-1616972-56.patch | 16.75 KB | Schnitzel |
#52 | taxonomy-term-label-1616972-52.patch | 16.44 KB | Berdir |
#49 | 1616972-49-taxonomy-replace_term_name.patch | 16.43 KB | Berdir |
#39 | 1616972-39-taxonomy-replace_term_name.patch | 17.06 KB | Schnitzel |
Comments
Comment #1
pfrenssenComment #2
pfrenssenHere is an initial version, am curious if the testbot will like it. I already ran all taxonomy and translation tests, but not the entire suite.
I had to skip all terms that are originating from taxonomy_get_tree(). This function does not return full Term objects, so the Term::label() method can not be used. I left the original $term->name for these.
Ref. #870528: taxonomy_get_parents(), taxonomy_get_children(), and taxonomy_get_tree() do not return a full term objects.
Comment #4
pfrenssenJust ran this test locally and it returns green. The testbot reported a missing table. Trying again.
Comment #5
pfrenssen#2: 1616972-2-taxonomy-replace_term_name.patch queued for re-testing.
Comment #6
pfrenssenCool, the test passes now. I'll unassign myself. It would be a good idea if someone who has good knowledge of the Taxonomy internals can have a look at this, to see if there is a solution for the functions that do not return full Term objects.
Comment #7
webflo CreditAttribution: webflo commentedI'm working on it.
Comment #8
webflo CreditAttribution: webflo commentedComment #10
webflo CreditAttribution: webflo commented#8: 1616972-3-taxonomy-replace_term_name.patch queued for re-testing.
Comment #11
webflo CreditAttribution: webflo commentedConverted all tests to $term->label()
Comment #13
pfrenssenAre you sure about using $term->label() as a parameter to taxonomy_term_load_multiple()? I have intentionally skipped all these since I thought it was the intention to use $term->label() only when outputting to the screen, as is done in the issue that is referenced in the summary: #1616962: Replace $node->title with $node->label().
Comment #14
webflo CreditAttribution: webflo commentedYes the failing test is unrelated to this patch. Re-run!
Comment #15
webflo CreditAttribution: webflo commented#11: 1616972-4-taxonomy-replace_term_name.patch queued for re-testing.
Comment #17
webflo CreditAttribution: webflo commented#11: 1616972-4-taxonomy-replace_term_name.patch queued for re-testing.
Comment #18
fagoYep, places where we edit or query for the name should stay with $term->name. $term->label() could be altered to point to something else, what would make this break. The same way, I think we should stay with the name in term-view templates and token replacements for now as both specifically refer to using the name.
Also see http://drupal.org/node/1616962#comment-6106630 for some examples.
Comment #19
webflo CreditAttribution: webflo commentedRemoved the changes around taxonomy_term_load_multiple(). I found a few more term names in forum and taxonomy module. I think tokens should be language aware and generated with the right language in context.
Comment #21
fagoTrue, but we have language aware getters for that (which won't work for properties yet).
Comment #22
webflo CreditAttribution: webflo commentedThird parameter needs to be NULL.
Comment #23
c31ck CreditAttribution: c31ck commentedPatch applies cleanly and does not contain any coding style issues. I did a search for any remaining $term->name that should be replaced but couldn't find any. However, we should only replace $term->name with $term->label() when we are referring to the term, not when we are explicitly working with the term name. More info is available in a comment by fago on the parallell issue: http://drupal.org/node/1616962#comment-6106630
I think we should stick with the $term->name because we're changing the $term->name directly here.
I think we should stick with the $term->name because we're changing the $term->name directly here.
The term name in templates should probably stay the term name. If we change this, we should rename the variable to term_label.
The term name in templates should probably stay the term name. If we change this, we should rename the variable to label.
Comment #24
gaspaio CreditAttribution: gaspaio commentedA tiny change to the name of a t() argument, from %name to %label, since its value is now $term->label().
Comment #25
gaspaio CreditAttribution: gaspaio commentedCreated a follow-up on adding a token for $term->label() : #1632720: Create tokens for entity labels.
Comment #26
webflo CreditAttribution: webflo commentedComment #28
webflo CreditAttribution: webflo commentedRerolled after tests moved to PSR-0.
Comment #29
fgmJust a few things I think might warrant changing:
We might want to type-hint $term as Term, and document the params.
This check may not be sufficient, better check if $tag instanceof EntityInterface to make sure it supports the method.
Comment #30
webflo CreditAttribution: webflo commentedAdd the type-hinting to taxonomy_term_confirm_delete() and instanceof EntityInterface in taxonomy_implode_tags() to make sure that Term::label() exists.
Comment #31
BerdirThis function is used as a title callback for two menu router items. This is exactly the use case that we now have for entity_page_label(). Let's remove this function in a follow-up issue and use entity_page_label() instead.
Otherwise, this looks ready for me. Let's get it in.
Comment #32
fagoThat would break things once the label is not pointing to the name anymore!
Looks wrong.
What is the name used for? Then, if it's the label it should be called that way.
Again, that variable is supposed to contain the term name. So it would be rather confusing it does not once the label points to something else. That said, I think we should leave templates alone for now. Converting them could be a separate issue, e.g. if the variable holds the label it should be called that way.
Comment #33
Schnitzel CreditAttribution: Schnitzel commentedworking on this
Comment #34
Schnitzel CreditAttribution: Schnitzel commentedfixxed the issues raised by fago
Comment #35
BerdirAs discussed, this means that the term overview will still display the term name. That's wrong.
IMHO, we should rename the variable to term_label and use that. Same for various forum preprocess functions for both terms and nodes.
Fine with doing that in a follow-up, though.
Comment #36
Berdirdid not mean to set to needs work.
Comment #37
fgmFollowup created in #1642070: Make use of entity labels in templates.
Comment #38
fagoSry for missing that earlier, but we cannot switch to entity_load() here. That not-entity-load version of taxonomy_get_tree() is need in order to avoid memory issues in cases like this one. There is an issue somewhere which did that because of memory issues + performance penalties with entity_load() due to all the fields being loaded as well. So I don't think we can change that here now. :/
However, that feels very odd. Just being able to use $term->label() partly because of that would make it quite random where it's used and where not. My feeling is that we have to convert to entities at some point and solve the performance problems somehow differently...?
Same here.
and here.
and here.
Another glitch, this compares labels to names.
Again entity load issue.
again.
again.
Comment #39
Schnitzel CreditAttribution: Schnitzel commentedDiscussed this Issue with @Webflo and @Gabor
We agree it would probably be pretty bad in memory if we load 100 terms (the default) on the taxonomy_overview_terms() page and also taxonomy_form_term (where it shows you all terms to select as a relation parent)
So we removed it from there.
But for the other places like forum and also hook_options_list() we should load the entities to have the right labels/names.
We should create a follow up for taxonomy_overview_terms() and taxonomy_form_term().
Comment #40
Schnitzel CreditAttribution: Schnitzel commentedoh shit, the "16.42 KB" and the "2.6 KB" is the correct one... (so nr 3 & 4)
Comment #41
fagoActually, that's the most problematic one. By default, this would load the whole vocabulary anyway, so if that blows up your site it will blow up your edit form. If it doesn't blow up, the performance decrease would be more relevant on the node edit form than on the taxonomy admin page as well.
Thus, once we start with going with entities there, we can do it everywhere. I tend to think that's the only way we can proceed for having a proper multilingual support for that. So we'd have the performance implications for that or we find other ways to improve it.
Comment #42
Schnitzel CreditAttribution: Schnitzel commentedcorrect, but after how many entities to load we talk about performance issues or memory problems? Because we could hope that somebody which has a lot of terms uses autocomplete on their taxonomy term field. But yes this is only an assumption.
I also don't see another possibility, we could now start with making entities loading faster, but this would stop our progress on multilanguage....
Should we go back and use entity_load everywhere and make a followup for the speed?
Comment #43
fagosee #556842: taxonomy_get_tree() memory issues.
I'd like to have catch to weigh on this as he is both, taxonomy and performance expert.
Comment #44
BerdirSorry, I have missed the performance issue here. I very much doubt that we can use entity_load() in taxonomy_get_tree(), not until we have some sort of lazy loading for entities, see #1237636: Entity lazy multiple front loading. Once we have an interface/pattern/implementation for that, we might be able to make this really nice and avoid having to load all fields when you just want to display the label() and stuff like that.
No sure what to do here until then. We could leave out these cases, create a follow-up issue and add a @todo to all affected locations. Similar to various places in the corresponding node label issue that adds @todo's for all places that load pseudo $node objects directly with db_query().
Comment #45
Schnitzel CreditAttribution: Schnitzel commentedunassigning from me
Comment #46
Gábor Hojtsy#1616962: Replace $node->title with $node->label() is now in core, so let's get going again with this!
Comment #47
fgm#39: 1616972-39-taxonomy-replace_term_name.patch queued for re-testing.
Comment #49
BerdirRe-rolled.
Comment #50
Berdir#49: 1616972-49-taxonomy-replace_term_name.patch queued for re-testing.
Comment #52
BerdirRe-roll.
Comment #53
Gábor Hojtsy#52: taxonomy-term-label-1616972-52.patch queued for re-testing.
Comment #55
Schnitzel CreditAttribution: Schnitzel commentedwill fix this in Munich :)
Comment #56
Schnitzel CreditAttribution: Schnitzel commentedrerolling, should apply
Comment #57
Schnitzel CreditAttribution: Schnitzel commentedhere some performance analysis:
Admin Taxonomy List
- created 800 terms
- viewing term list (admin/structure/taxonomy/)
- "ab -n 20 -c 1" (with cookie for user1)
with $term->name (old version, no loading of entities)
Time taken for tests: 18.431 seconds
Time per request: 921.571 [ms] (mean)
Total Incl. MemUse (bytes): 8,930,184 bytes
with $term->label() (new version, loading of entities)
Time taken for tests: 22.156 seconds
Time per request: 1107.786 [ms] (mean)
Total Incl. MemUse (bytes): 10,842,576 bytes
Analysis
200ms slower (which is 20% of the overall page load)
Memory +2MB
Create Node with Taxonomy Field
100 Terms
- created 100 terms
- Added TermReference Field to Contenttype Page
- Creating Content (node/add/page)
- "ab -n 20 -c 1" (with cookie for user1)
with $term->name (old version, no loading of entities)
Time taken for tests: 3.689 seconds
Time per request: 184.438 [ms] (mean)
with $term->label() (new version, loading of entities)
Time taken for tests: 4.235 seconds
Time per request: 211.755 [ms] (mean)
Analysis
27ms slower (which is 14% slower of the overall page load)
800 Terms
- created 800 terms
- Added TermReference Field to Contenttype Article
- Creating Content (node/add/article)
- "ab -n 20 -c 1" (with cookie for user1)
with $term->name (old version, no loading of entities)
Time taken for tests: 5.273 seconds
Time per request: 263.629 [ms] (mean)
Total Incl. MemUse (bytes): 5,728,624 bytes
with $term->label() (new version, loading of entities)
Time taken for tests: 9.221 seconds
Time per request: 461.042 [ms] (mean)
Total Incl. MemUse (bytes): 6,855,104 bytes
Analysis
200ms slower (which is 75% of the overall page load)
Memory +1.1MB
Forum
12 Forums
- created 12 terms in forum vocabulary
- viewing forum frontpage (/forum)
- "ab -n 20 -c 1"
with $term->name (old version, no loading of entities)
Time taken for tests: 2.673 seconds
Time per request: 133.656 [ms] (mean)
with $term->label() (new version, loading of entities)
Time taken for tests: 2.718 seconds
Time per request: 135.884 [ms] (mean)
Analysis
2ms slower (which is 1% of the overall page load)
80 Forums
- created 80 terms in forum vocabulary
- viewing forum frontpage (/forum)
- "ab -n 20 -c 1"
with $term->name (old version, no loading of entities)
Time taken for tests: 5.054 seconds
Time per request: 252.681 [ms] (mean)
with $term->label() (new version, loading of entities)
Time taken for tests: 5.501 seconds
Time per request: 275.041 [ms] (mean)
Analysis
25ms slower (which is 9% of the overall page load)
160 Forums
- created 80 terms in forum vocabulary
- viewing forum frontpage (/forum)
- "ab -n 20 -c 1"
with $term->name (old version, no loading of entities)
Time taken for tests: 7.790 seconds
Time per request: 389.487 [ms] (mean)
with $term->label() (new version, loading of entities)
Time taken for tests: 8.784 seconds
Time per request: 439.175 [ms] (mean)
Analysis
50ms slower (which is 12% of the overall page load)
Comment #58
webchickThanks for the benchmarks... yikes! :)
I asked Schnitzel to look for a place we might be missing an entity_load_multiple() (rather than an entity_load()) as it could account for this happening.
Comment #59
BerdirMy guess is that those performance differences are because of the taxonomy_get_tree() changes that now do a full entity load if the argument is set to TRUE. Not sure what to do about that.
Comment #60
Schnitzel CreditAttribution: Schnitzel commented@berdir
nope, then it should only be 200msec longer.
I checked with xhprof and for "Admin Taxonomy List" and "Create Node with Taxonomy Field" the function taxonomy_get_tree jumps from
30ms to 200ms
while the whole pageload is almost double for "Create Node with Taxonomy Field"
Comment #61
Schnitzel CreditAttribution: Schnitzel commentedwell actually it only jumps 200ms on top, sorry didn't yet had enough hungarian chocolate *g*
so the admin taxonomy list jumps from 921.571 [ms] to 1107.786 [ms]
while Create Node with Taxonomy Field jumps from 263.629 to 461.042 [ms]
so both 200ms, just the overall pagespeed is different
Comment #62
Schnitzel CreditAttribution: Schnitzel commentedas discussed with webchick the performance regressions are as expected.
When a page loads 800 terms it is 200ms slower, if it loads 100 terms its 27ms slower. And this does not matter if on Forum, NodeAdd or Taxonomy List.
we also discussed if we keep the "$load_entities = FALSE" argument on taxonomy_get_tree(). To not mix too many things in this issue and there can be a case where not loading the entities is interesting (when you only need the TermID), we will not touch this here. So we will make a followup for this.
Attached is a patch which also uses entities for taxonomy term list overview.
Comment #63
Gábor HojtsyAssigning to catch as per discussion with @webchick following @catch's approval for the assignment itself :)
Comment #64
catchSo viewing a node we already load full entities in taxonomy_field_formatter_prepare_view(), there should only be a very small hit for the extra method call there.
The node/add and admin screen regressions are very unfortunate, we already went through this with #870528: taxonomy_get_parents(), taxonomy_get_children(), and taxonomy_get_tree() do not return a full term objects then made the full objects optional for the same reason.
I'd be tempted to commit this with the known regression, but then upgrade #556842: taxonomy_get_tree() memory issues and/or #30993: Scaleable/themeable taxonomy selection widget to try to fix/mitigate the taxonomy_get_tree() issues we're making worse here?
Comment #65
Gábor HojtsyAll right, thanks for the review. Let's do that then :)
Comment #66
BerdirI was thinking along the suggestions from @catch in #64 as well, fine with me.
Can someone open a follow-up to fix the term/forum templates? Those are right now still using $term->name directly, we need to fix that.
Comment #67
Schnitzel CreditAttribution: Schnitzel commented@berdir
There is already a followup from the node->label() discussion:
#1642070: Make use of entity labels in templates
Comment #68
webchickOk, now that I'm fairly sure that catch won't kill me if I commit this... ;)
Committed and pushed to 8.x. Thanks!
This needs a change notice, so escalating. Also, #556842: taxonomy_get_tree() memory issues seems to already be a critical so I think we're good there. #30993: Scaleable/themeable taxonomy selection widget is still listed as a "major feature request" but I think that's appropriate, given that 800 terms in a drop-down is an edge case, and likely anyone hitting that can install hierarchical_select module or prepopulate or something else to work around it.
Comment #69
Gábor HojtsyChange notice at http://drupal.org/node/1739820
Comment #70
tim.plunkettFollow-up bug caused by this issue: #1754070: Test coverage for Editing and re-saving a node with tagged taxonomy terms removes terms from node
Comment #71
Gábor HojtsyDone, off sprint. Thanks all!
Comment #72.0
(not verified) CreditAttribution: commentedfixed typo