Problem/Motivation
On "Your Posts" page (user/%/track and tracker/%) post are not being sorted correctly. Not all posts move up to the top when they are updated. It still reports when there are new comments, but it doesn't move those posts to the top of the list as it should.
It would seem that this is because the denormalized data kept for the tracker updates for the current user, but not all users.
Proposed resolution
Fix the update of the rows in the tracker_user table so that the modification timestamp is updated for all users not just the user that posted the update.
Remaining tasks
- Review the test and the fix
User interface changes
None (except now the order of posts will be correct)
API changes
None.
Steps to reproduce
This issue is a little complex, but we should be able to add a test relatively easily out of this.
- Get yourself a site that has the tracker module enabled, and a couple of users, who can post content and comments.
- With user1 create two bits of content, say content A and content B.
- With user2 add a comment to each of the bits of content.
- Confirm the order of the on the user/%/track page of user2, note which piece of content is at the bottom.
- Using user1 create a comment on that bit on content from the previous step.
- Now revisit the track page for user2 we would expect that now the content that was just updated with a comment should appear at the top of the list, but it'll be stuck to the bottom :(
| Task | Novice task? | Contributor instructions | Complete? |
|---|---|---|---|
| Create a patch | Instructions | Completed in #23 | |
| Update the issue summary | Instructions | Completed in #29 | |
| Add automated tests | Instructions | Completed in #36 | |
| Improve patch documentation or standards (for just lines changed by the patch) | Novice | Instructions | Completed in #37 |
| Manually test the patch | Novice | Instructions | Completed in #32 |
| Add steps to reproduce the issue | Novice | Instructions | Completed in #31 |
| Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards | Instructions |
Original report by @m1r1k
Tracker pages which use tracker_page() as page callback has wrong results ordering.
// This array acts as a placeholder for the data selected later
// while keeping the correct order.
$nodes = $query
->addTag('node_access')
->fields('t', array('nid', 'changed'))
->condition('t.published', 1)
->orderBy('t.changed', 'DESC')
->limit(25)
->execute()
->fetchAllAssoc('nid');
here there is even extra query to get nid in correct order, but then we have simple condition in the nodes query
WHERE n.nid IN (:nids) that does not order, only filter results.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | drupal-2224917-tracker-page.patch | 3.64 KB | steven jones |
| #37 | drupal-2224917-tracker-incorrect-ordered.patch | 3.73 KB | steven jones |
| #36 | drupal-2224917-tracker-incorrect-ordered-just-test.patch | 2.89 KB | steven jones |
| #23 | 2224917.patch | 840 bytes | drumm |
| #16 | tracker-tracker-pages-have-wrong-ordering-2224917-16.patch | 4.69 KB | m1r1k |
Comments
Comment #2
m1r1k commentedRemoved "Changed" column from node table, because it is wrong for tracker page.
Comment #3
m1r1k commentedComment #4
tvn commentedComment #5
yesct commentedhttps://drupal.org/contributor-tasks/write-tests is instructions for adding automatic tests.
can we even test this?
I'm not sure about usual way for drupal 7.x
---
this also needs a review.
https://drupal.org/contributor-tasks/review is instructions for reviewing.
---
please make a comment if someone starts to do either of those tasks.
Comment #6
tvn commentedpwolanin reviewed this patch today and it needs some more work, updating status accordingly.
Comment #7
m1r1k commentedClean up the code. Add test case for this case.
Comment #9
pedrop commentedI wanted to test the patches manually but can't reproduce the issue. Please provide me exact steps how to reproduce it.
Comment #10
mgiffordtracker_page() has changed a lot in the git repo. I couldn't apply it locally.
I came from #2130537: user/%/track not sorting correctly
Comment #11
m1r1k commentedWell, after one more code review (@pedrop could not reproduce it that made me worry) I've found out that everything works fine.
I had to read these line more carefully
Unfortunately it wasn't obviously for me, because my patch fixed such problems https://drupal.org/node/2130537#comment-8601937
It was because tracker module uses $node->changed here:
but uses tracker->changed ($node->last_activity) here:
when all results were ordered by tracker->changed.
Comment #12
m1r1k commentedComment #13
m1r1k commentedHow about such improvements?
Comment #14
m1r1k commentedComment #16
m1r1k commentedAdd some related modifications to tests
Comment #17
giorgoskI would ask you to consider this as Major
as it is affecting all users of d.o.
noone at this time can track their d.o. posts sorted by date
I know there is the issue tracker on the dashboard and clicking on more from there
but that solves only HALF of the problem
what about regular posts ? (not issues)
for more details look at
this postponed issue > #2130537: user/%/track not sorting correctly
and a long time workaround since the previous issue which now is not working > #2133945: "Your posts" dashboard block sorts items on the last comment
and was decided as MAJOR for the very reason I am posting about
Comment #18
drummWhat I see in
_tracker_add()in 8.x is:The second
db_merge()looks like it should update all rows matching the nid, not just the one user. The node is changed at the same time for everyone, and especially published or not the same for everyone.tracker_cron()looks like it has the correct logic.Comment #19
drummMaybe it is as simple as this. I'm guessing more tests would still be good.
Comment #21
drummAttached is a more-careful patch.
Comment #23
drummThis should fix the misuse of db_update.
Comment #24
drummThe way to test for this would be checking tracker page as another user sees it. The timestamps are updating for the commenter's tracker, but not everyone else's.
Comment #25
drummComment #26
drumm(Assigning to myself so I stop looking at my own patch.)
Comment #27
drumm23: 2224917.patch queued for re-testing.
Comment #28
steven jones commentedWorking on this at the contribution sprint, so assigning to myself.
Comment #29
steven jones commentedAdded a basic issue summary, and will continue to update it as I get to grips with this issue.
Comment #30
steven jones commentedComment #31
steven jones commentedAdded some steps to reproduce to the issue summary, I'm going to test the patchy patch now.
Comment #32
steven jones commentedPatch in #2224917: Tracker page doesn't order results properly fixes the issue for me.
I guess that for me the comment that has been changed should maybe be split so that it's directly above the db_update too, might make more sense when reading.
Also, setting back to needs work, as this thing needs a test, right?
Comment #33
steven jones commentedAdded the novice tasks stuff to the issue summary.
Comment #34
steven jones commentedComment #35
steven jones commentedSpoken to tvn, and I'm going to write some tests.
Comment #36
steven jones commentedWow that took a lot longer than I was expecting, and sadly I had to rely on the ordering in the HTML using a regex.
Here's a patch that includes just the test.
Comment #37
steven jones commentedAnd here's a patch that includes the fix as well.
Comment #38
steven jones commentedComment #40
steven jones commentedMy work here is done, un-assigning myself.
Comment #41
drummLooks good to me.
Comment #42
alexpottCommitted d084d2d and pushed to 8.x. Thanks!
Comment #43
alexpottComment #44
steven jones commentedThanks very much Alex.
On the patch...
Comment #45
steven jones commentedHere's a re-roll for Drupal 7.
Comment #46
drummLooks good.
Comment #47
tvn commentedComment #48
tvn commentedComment #49
drummLet's keep "affects Drupal.org" since it hasn't made it into 7.x yet. Deploying later today.
Comment #50
drummNow deployed to Drupal.org. Since there isn't a DB update, the improved ordering will only be visible for recently-updated nodes. I'm okay with not having a DB update; updating the large, busy table would probably need a downtime scheduled, or careful batching.
Comment #51
drummSorry for all the tag noise.
Comment #53
liviepm commented37: drupal-2224917-tracker-incorrect-ordered.patch queued for re-testing.
Comment #55
johnpitcairn commentedMany thanks to those who worked on this.
Comment #56
steven jones commented45: drupal-2224917-tracker-page.patch queued for re-testing.
Comment #57
steven jones commentedThe fail in #54 looks like a testbot error.
Comment #58
drummNot exactly a testbot error, just the 8.x patch being re-queued against 7.x. #45 is still good to go.
Comment #59
steven jones commentedSorry I meant the fail in #52 was a random testbot fail, I re-queued the patch, and all the tests passed fine.
Comment #60
David_Rothstein commentedCommitted to 7.x - thanks!