There's a code block like the following in the statistics_node_tracker function.

$result = pager_query('SELECT a.aid, a.timestamp, a.url, a.uid, u.name
                        FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid
                        WHERE a.path LIKE \'node/%d%%\'' . tablesort_sql($header),
                        30, 0, NULL, $node->nid);

It definitely seems wrong to me setting $node->nid in 'LIKE' parameter like above.

When you have nodes with nid 123 and another with 1234, you'll get access logs of both nodes if you query with $node->nid as 123.

I want to say another thing. This is just my opinion for improvement. Why don't you query access logs first for users. I don't think viewing all access logs by time is a good idea.

Instead query for users with access logs displaying his or her first and last access time. If you want to see all his or her logs, then there's a link to detailed logs. How about that? (Actually I am running my Drupal installation customized as such...) A query for that will be like this(for MySQL 5)

select u.uid, u.name, a.first_access, b.last_access
from {users} u
left join ( select uid, min(timestamp) first_access from {accesslog} where path like \'node/%d%%\' group by uid ) a on u.uid=a.uid
left join ( select uid, max(timestamp) last_access from {accesslog} where path like \'node/%d%%\' group by uid ) b on u.uid=b.uid
where u.uid > 0 order by a.first_access desc

Comments

dave reid’s picture

Version: 5.1 » 7.x-dev
Issue tags: +statistics

Marked #363283: node/id/track wrong for a single digit id as a duplicate of this issue. Moving to 7.x to get fixed first.

dave reid’s picture

Confirmed this is a bug.

I did a little search back through old versions of statistics.module (D5) and it appears that we have always searched by "LIKE 'node/%d%%'" when we only need to use "= 'node/%d'" since we use $_GET['q'] to insert into the accesslog.

karschsp’s picture

Status: Active » Needs review
StatusFileSize
new1.05 KB

here's a patch that should fix this.

mr.baileys’s picture

Status: Needs review » Needs work
Issue tags: +Quick fix

As Dave Reid suggested in #2: I don't think there's a reason to leave the "LIKE"-portion lingering if we're dropping the '%', so it should probably be replaced with '='.

Also, in this case I think we should replace the single-quotes by double-quotes so we can get rid of the ugly
\'node/%d\''

damien tournoud’s picture

I believe the initial idea was to count every "node/xxx/yyy" where yyy can be /edit, /talk, /...

In that case, the correct query would be:

+    $result = pager_query("SELECT a.aid, a.timestamp, a.url, a.uid, u.name FROM {accesslog} a LEFT JOIN {users} u ON a.uid = u.uid WHERE a.path LIKE '%s' " . tablesort_sql($header), 30, 0, NULL, 'node/' . $node->nid . '/%');

... but of course... we also need to convert this to DB:TNG and add a test ;)

dave reid’s picture

Actually I think testing for LIKE "node/x/" will not work because the node-view locations are just "node/x". We'll probably need to use a.path = "node/x" OR a.path LIKE "node/x/%"

dave reid’s picture

Assigned: Unassigned » dave reid
Status: Needs work » Needs review
Issue tags: +Needs backport to D6, +Needs tests, +Needs backport to D5
StatusFileSize
new2.12 KB

Patch attached that coverts to new DBTNG pager/tablesort and fixes the SQL. Now I just need to get a quick test written.

dave reid’s picture

Fixed a couple other pager queries.

dries’s picture

Status: Needs review » Needs work

This patch will need to be re-rolled for Drupal 7. A statistics.module DBTNG patch just landed and conflicts with this one. Thanks!

berdir’s picture

StatusFileSize
new1.17 KB

Re-roll.

berdir’s picture

Status: Needs work » Needs review

Update status.

dries’s picture

When looking at this patch, all of a sudden, I find myself wondering why we care about 'node/$nid/%' to begin with. Isn't 'node/$nid' enough?

dave reid’s picture

@Dries: That's what I thought originally as well, but it appears to be intentional since the introduction of this code. As Damien said in #5, "I believe the initial idea was to count every "node/xxx/yyy" where yyy can be /edit, /talk, /..."

dries’s picture

Status: Needs review » Fixed

Committed to CVS HEAD. We can argue about the paths to include in a follow-up issue, if necessary.

dave reid’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Reviewed & tested by the community
Issue tags: -Needs backport to D6, -Needs tests
StatusFileSize
new1.08 KB

Backported for Drupal 6.

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

Status: Fixed » Closed (fixed)
Issue tags: -Quick fix, -statistics, -Needs backport to D5

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