1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Likes don't update after username change?

Discussion in 'Resolved Bug Reports' started by RastaLulz, Nov 27, 2011.

  1. RastaLulz

    RastaLulz Well-Known Member

    Hello,

    I'm not sure if this is a bug, or something that was intended to reduce the amount dynamic data taken from MySQL.

    When a user likes a post, then has their username changed, it doesn't seem to update on the post it self.

    For example, it shows that Craigypoo liked the post:
    [​IMG]

    Yet when you click his name, it shows his current and up to date username, Sledmore:
    [​IMG]
     
  2. Vincent

    Vincent Well-Known Member

  3. Kier

    Kier XenForo Developer Staff Member

    This is working as designed - the names will update next time the content is liked or unliked, but it's simply not practical to go through every content item rebuilding the likes cache whenever a username is altered.
     
    DeltaHF, digitalpoint and RastaLulz like this.
  4. digitalpoint

    digitalpoint Well-Known Member

    Was actually just going to reply with the same thing. The DB would come to a crawl with the nasty full table scan query needed to update the username in realtime for likes... Not unlike how vBulletin poops itself when it gets to the pmtext table when you change a username (assuming you have a lot of PMs in the table of course).
     
  5. digitalpoint

    digitalpoint Well-Known Member

    Actually, I gave this some more thought... and it could be done without too much nastiness with the database...

    Something like this (this is just off the top of my head, so obviously you want want to sanitize variables:

    Code:
    'UPDATE xf_post
    SET like_users = REPLACE(like_users, 'i:' . $userId . ';s:8:"username";s:' . strlen($oldUsername) . ':"' . $oldUsername .  '";', 'i:' . $userId . ';s:8:"username";s:' . strlen($newUsername) . ':"' . $newUsername .  '";')
    WHERE post_id IN (SELECT content_id FROM xf_liked_content WHERE content_type = 'post' AND like_user_id = $userId)'
    Since we already know the exact posts that have a cache that would need to be updated, you can use the sub-query to just do the replace on those records (and not needing to do a full table scan). Even if someone did a ton of likes (like 10,000+ or something), the query should just take a second since it's only looking through the records actually needed.

    And triggering a query that might take a second is perfectly fine considering only an admin can change a username anyway (not something the end user can trigger over and over).
     
    Eagle, Darkimmortal and CyclingTribe like this.
  6. Kier

    Kier XenForo Developer Staff Member

    This has been addressed in XenForo 1.2
     
    R_A, faeronsayn, Walter and 10 others like this.
  7. CyclingTribe

    CyclingTribe Well-Known Member

    Nice one! (y)
     

Share This Page