Make WordPress Core

Opened 7 years ago

Closed 5 years ago

#4170 closed defect (bug) (fixed)

author pages do an uncached user_nicename lookup

Reported by: andy Owned by: westi
Milestone: 2.8 Priority: normal
Severity: minor Version: 2.1
Component: Optimization Keywords: has-patch tested
Focuses: Cc:


This isn't an issue until you have a large users table, but these lookups should be cached. Attaching a patch.

Attachments (3)

nicename.diff (1.7 KB) - added by andy 7 years ago.
4170.diff (2.7 KB) - added by Denis-de-Bernardy 5 years ago.
4170.2.diff (3.4 KB) - added by Denis-de-Bernardy 5 years ago.

Download all attachments as: .zip

Change History (15)

andy7 years ago

comment:1 Nazgul7 years ago

  • Keywords has-patch added

comment:2 rob1n7 years ago

Shouldn't it be get_user_id_by_nicename()? Since it only returns the ID, as far as I can tell...

To me, get_user_by_nicename() returns an user object with that nicename.

comment:3 rob1n7 years ago

  • Keywords 2nd-opinion added

comment:4 rob1n7 years ago

  • Milestone changed from 2.2 to 2.3
  • Owner changed from anonymous to rob1n

comment:5 andy7 years ago

Sure, whatever you want to call it.

comment:6 f00f7 years ago

Looks ok.
I agree with rob1n that the function name should be changed. Furthermore IMHO the cache name should also reflect that user ids are cached, not nicenames. I'd call it user_id_by_nicename or sth. like that.

comment:7 rob1n7 years ago

  • Owner rob1n deleted

comment:8 westi6 years ago

  • Keywords needs-patch added; has-patch 2nd-opinion removed
  • Milestone changed from 2.5 to 2.6
  • Owner set to westi

Nice chunky patch that could do with some love as it no longer applies.

Pushing to 2.6 with needs-patch but will possibly accept for 2.5 if patch is updated.

Denis-de-Bernardy5 years ago

comment:9 Denis-de-Bernardy5 years ago

  • Component changed from Administration to Optimization
  • Keywords has-patch tested added; needs-patch removed
  • Milestone changed from 2.9 to 2.8

new patch does the following, against 2.8/trunk:

  • add a get_user_by_nicename() function that caches its results
  • sets and flushes the cache where appropriate
  • uses the function in WP_Query

Denis-de-Bernardy5 years ago

comment:11 ryan5 years ago

Should we pattern after get_term_by() and have one function -- get_user_by() -- for handling retrieving by various fields? Also, I prefer the term "slug" to "nicename". I think it makes it clearer what the field is. So, get_user_by('slug', 'admin');

comment:12 ryan5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [10992]) Cache user lookups made by nicename. Add get_user_by(). fixes #4170

Note: See TracTickets for help on using tickets.