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.

  1. Get yourself a site that has the tracker module enabled, and a couple of users, who can post content and comments.
  2. With user1 create two bits of content, say content A and content B.
  3. With user2 add a comment to each of the bits of content.
  4. Confirm the order of the on the user/%/track page of user2, note which piece of content is at the bottom.
  5. Using user1 create a comment on that bit on content from the previous step.
  6. 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 :(
Contributor tasks needed
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.

Comments

Status: Needs review » Needs work

The last submitted patch, tracker-tracker-pages-have-wrong-ordering-1.patch, failed testing.

m1r1k’s picture

Removed "Changed" column from node table, because it is wrong for tracker page.

m1r1k’s picture

Status: Needs work » Needs review
tvn’s picture

Issue tags: +affects drupal.org
yesct’s picture

Issue tags: +Needs tests

https://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.

tvn’s picture

Status: Needs review » Needs work

pwolanin reviewed this patch today and it needs some more work, updating status accordingly.

m1r1k’s picture

Status: Needs work » Needs review
StatusFileSize
new5.68 KB
new6.1 KB

Clean up the code. Add test case for this case.

Status: Needs review » Needs work

The last submitted patch, 7: tracker-tracker-pages-have-wrong-ordering-2224917-7.patch, failed testing.

pedrop’s picture

Status: Needs work » Needs review

I wanted to test the patches manually but can't reproduce the issue. Please provide me exact steps how to reproduce it.

mgifford’s picture

tracker_page() has changed a lot in the git repo. I couldn't apply it locally.

I came from #2130537: user/%/track not sorting correctly

m1r1k’s picture

Well, 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

foreach ($result as $node) {
      $node->last_activity = $nodes[$node->nid]->changed;
      $nodes[$node->nid] = $node;
    }

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:

        'title' => array('data' => l($node->title, 'node/' . $node->nid) . ' ' . theme('mark', array('type' => node_mark($node->nid, $node->changed)))),

but uses tracker->changed ($node->last_activity) here:

       'last updated' => array('data' => t('!time ago', array('!time' => format_interval(REQUEST_TIME - $node->last_activity)))),

when all results were ordered by tracker->changed.

m1r1k’s picture

Status: Needs review » Needs work
m1r1k’s picture

How about such improvements?

m1r1k’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 13: tracker-tracker-pages-have-wrong-ordering-2224917-13.patch, failed testing.

m1r1k’s picture

Status: Needs work » Needs review
StatusFileSize
new2.3 KB
new4.69 KB

Add some related modifications to tests

giorgosk’s picture

Priority: Normal » Major

I 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

drumm’s picture

Version: 7.x-dev » 8.x-dev

What I see in _tracker_add() in 8.x is:

  // Update the node-level data.
  db_merge('tracker_node')
    ->key('nid', $nid)
    ->fields(array(
      'changed' => $changed,
      'published' => $node->status,
    ))
    ->execute();

  // Create or update the user-level data.
  db_merge('tracker_user')
    ->keys(array(
      'nid' => $nid,
      'uid' => $uid,
    ))
    ->fields(array(
      'changed' => $changed,
      'published' => $node->status,
    ))
    ->execute();

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.

drumm’s picture

StatusFileSize
new525 bytes

Maybe it is as simple as this. I'm guessing more tests would still be good.

Status: Needs review » Needs work

The last submitted patch, 19: 2224917.patch, failed testing.

drumm’s picture

Status: Needs work » Needs review
StatusFileSize
new834 bytes

Attached is a more-careful patch.

Status: Needs review » Needs work

The last submitted patch, 21: 2224917.patch, failed testing.

drumm’s picture

Status: Needs work » Needs review
StatusFileSize
new840 bytes

This should fix the misuse of db_update.

drumm’s picture

The 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.

drumm’s picture

drumm’s picture

Assigned: m1r1k » drumm

(Assigning to myself so I stop looking at my own patch.)

drumm’s picture

23: 2224917.patch queued for re-testing.

steven jones’s picture

Assigned: drumm » steven jones

Working on this at the contribution sprint, so assigning to myself.

steven jones’s picture

Issue summary: View changes
Issue tags: -Needs issue summary update

Added a basic issue summary, and will continue to update it as I get to grips with this issue.

steven jones’s picture

Issue summary: View changes
steven jones’s picture

Issue summary: View changes

Added some steps to reproduce to the issue summary, I'm going to test the patchy patch now.

steven jones’s picture

Assigned: steven jones » Unassigned
Issue summary: View changes
Status: Needs review » Needs work

Patch 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?

steven jones’s picture

Issue summary: View changes

Added the novice tasks stuff to the issue summary.

steven jones’s picture

Issue summary: View changes
steven jones’s picture

Assigned: Unassigned » steven jones
Issue summary: View changes

Spoken to tvn, and I'm going to write some tests.

steven jones’s picture

Status: Needs work » Needs review
StatusFileSize
new2.89 KB

Wow 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.

steven jones’s picture

Issue tags: -Needs tests, -Novice
StatusFileSize
new3.73 KB

And here's a patch that includes the fix as well.

steven jones’s picture

Issue summary: View changes

The last submitted patch, 36: drupal-2224917-tracker-incorrect-ordered-just-test.patch, failed testing.

steven jones’s picture

Assigned: steven jones » Unassigned

My work here is done, un-assigning myself.

drumm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

alexpott’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Committed d084d2d and pushed to 8.x. Thanks!

alexpott’s picture

Version: 8.x-dev » 7.x-dev
steven jones’s picture

Assigned: Unassigned » steven jones

Thanks very much Alex.

On the patch...

steven jones’s picture

Assigned: steven jones » Unassigned
Status: Patch (to be ported) » Needs review
StatusFileSize
new3.64 KB

Here's a re-roll for Drupal 7.

drumm’s picture

Status: Needs review » Reviewed & tested by the community

Looks good.

tvn’s picture

Issue tags: +needs drupal.org deployment
tvn’s picture

drumm’s picture

Issue tags: +affects drupal.org

Let's keep "affects Drupal.org" since it hasn't made it into 7.x yet. Deploying later today.

drumm’s picture

Issue tags: -needs drupal.org deployment

Now 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.

drumm’s picture

Issue tags: -Drupal.org 7.1

Sorry for all the tag noise.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 45: drupal-2224917-tracker-page.patch, failed testing.

liviepm’s picture

The last submitted patch, 37: drupal-2224917-tracker-incorrect-ordered.patch, failed testing.

johnpitcairn’s picture

Many thanks to those who worked on this.

steven jones’s picture

Status: Needs work » Needs review
steven jones’s picture

The fail in #54 looks like a testbot error.

drumm’s picture

Status: Needs review » Reviewed & tested by the community

Not exactly a testbot error, just the 8.x patch being re-queued against 7.x. #45 is still good to go.

steven jones’s picture

Sorry I meant the fail in #52 was a random testbot fail, I re-queued the patch, and all the tests passed fine.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed e052539 on 7.x
    Issue #2224917 by m1r1k, Steven Jones, drumm: Fixed Tracker page doesn't...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.