The order ionce clicked on "visitors" on the access logs part, is weird. first it sorts by username (0-9,a-z) which is good but once it gets to ip addresses, there is no logic and hence you cant find an ip address the easy way. try to lookup 11.12.13.14 in http://drupal.org/admin/logs/visitors?page=0&sort=asc&order=Visitor and you will see there is no logic there.

I thought ordening would be based on first octet, second octet, third and fourt (hence 1.2.3.4 would be before 2.255.255.255) but is not. I think there is some hash over the complete ip address and the ordening is done on that, because all other logic escapes me.

anyone cares to dig into this?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeryan’s picture

Project: Statistics Filter » Drupal core
Version: 4.6.x-1.x-dev » 4.6.0
Component: Code » statistics.module
Harry Slaughter’s picture

the query is getting both the username and the hostname (ip). all sorts are done on the username field only. as he prepares to display the results of the query, he swaps in the hostname if the username is empty. so the hostnames are never really sorted at all (and probably shouldn't be values in a sortable field :)

$rows[] = array($account->hits, ($account->uid ? theme('username', $account) : $account->hostname), format_interval(round($account->total / 1000)), $ban_link);

markus_petrux’s picture

Version: 4.6.0 » x.y.z
Category: bug » feature

This looks more like a feature request, and affects HEAD.

One solution to this problem would require to store IPs using a different format, maybe with the same approach implemented by phpBB. It uses CHAR(8) in the database, and converts the IP address to an hexadecimal value, where each part needs 2 bytes.

They use this functions:

function encode_ip($dotquad_ip) {
  $ip_sep = explode('.', $dotquad_ip);
  return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1], $ip_sep[2], $ip_sep[3]);
}
function decode_ip($int_ip) {
  $hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
  return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}

That way IPs can be sorted on a more logical manner and is more optimal than converting IPs to longs.

markus_petrux’s picture

Forgot to mention side effects related to such a change...

1) Stuff related to {access_log} table (statistics module).
2) Stuff related to {access} table (ip bans, etc.).
3) Watchdog.
4) Probably some contrib modules too.

I don't believe this will be done any time soon... and I can't think of any other reasonable way to sort IPs logically.

LAsan’s picture

Version: x.y.z » 7.x-dev

Did current versions taken this feature request in consideration?

Moving to current.

Dave Reid’s picture

Title: order "visitor" in stats odd » Ordering by 'Visitor' in access log pages does not sort IP addresses.
Category: feature » bug
aspilicious’s picture

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

Needs to be fixed first in D8.

bleen’s picture

Status: Active » Needs review
FileSize
72.19 KB
72.06 KB
576 bytes

WOW!! A seven-year-old issue... lets see if we cant just kill this one.

The attached patch fixes this "enough" IMO by always sorting the ip (ASC), but since this particular column in this particular table actually contains data from two DB columns (name & ip) it does not obey the tablesort link in the header.

I think this is an acceptable solution in this case though. If we want we can open up a feature request for orderByHeader() to accept multiple fields, but that is out of scope for this issue me thinks.

screenshot
screenshot

timmillwood’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me, a very simple solution to the issue that has the possibility to get back-ported to D7 too.

Although, my preference would be to remove all of the access_log functionality from D8 and just keep the node_counter.

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +needs profiling

There's no index on hostname, could we get a before/after EXPLAIN for the query with the default sort? 'needs profiling' isn't quite the right tag but in the interests of not creating a new tag, adding that.

kscheirer’s picture

Status: Needs review » Reviewed & tested by the community

The explains are identical in all cases. Adding an index on accesslog.hostname did not alter the way either of these queries was executed. If we're sorting based on a calculated value like hits, I think there's no way to avoid using a temporary table.

Marking this as RTBC based on #9.

Without patch:

mysql> EXPLAIN SELECT a.uid AS uid, a.hostname AS hostname, u.name AS name, COUNT( a.uid ) AS hits, SUM( a.timer ) AS total FROM  `accesslog` a LEFT OUTER JOIN users u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name ORDER BY hits DESC;
+----+-------------+-------+--------+---------------+---------+---------+----------+------+---------------------------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref      | rows | Extra                           |
+----+-------------+-------+--------+---------------+---------+---------+----------+------+---------------------------------+
|  1 | SIMPLE      | a     | ALL    | NULL          | NULL    | NULL    | NULL     |   34 | Using temporary; Using filesort |
|  1 | SIMPLE      | u     | eq_ref | PRIMARY       | PRIMARY | 4       | d8.a.uid |    1 |                                 |
+----+-------------+-------+--------+---------------+---------+---------+----------+------+---------------------------------+

Patched:

mysql> EXPLAIN SELECT a.uid AS uid, a.hostname AS hostname, u.name AS name, COUNT(a.uid) AS hits, SUM(a.timer) AS total FROM accesslog a LEFT OUTER JOIN users u ON a.uid = u.uid GROUP BY a.hostname, a.uid, u.name ORDER BY hits DESC, a.hostname ASC;
+----+-------------+-------+--------+---------------+---------+---------+----------+------+---------------------------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref      | rows | Extra                           |
+----+-------------+-------+--------+---------------+---------+---------+----------+------+---------------------------------+
|  1 | SIMPLE      | a     | ALL    | NULL          | NULL    | NULL    | NULL     |   34 | Using temporary; Using filesort |
|  1 | SIMPLE      | u     | eq_ref | PRIMARY       | PRIMARY | 4       | d8.a.uid |    1 |                                 |
+----+-------------+-------+--------+---------------+---------+---------+----------+------+---------------------------------+
timmillwood’s picture

Sorry guys, I would rather see accesslog removed #1446956: Remove the accesslog from statistics

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Which was just committed.

kscheirer’s picture

Issue tags: -needs profiling

I think Dries trumped this issue in D8 :) - http://drupal.org/node/1446956#comment-6952152.

But we can still fix this in D7.

dcam’s picture

Status: Patch (to be ported) » Needs review
FileSize
556 bytes

Backported #8 to D7.

Status: Needs review » Needs work

The last submitted patch, 28175-15-access-log-sort.patch, failed testing.

mikeytown2’s picture

Status: Needs work » Needs review

#15: 28175-15-access-log-sort.patch queued for re-testing.

Test went fatal on "ShortcutSetsTestCase->testShortcutSetDeleteDefault()". Seems outside of the scope of the patch thus retesting it.

thedavidmeister’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I tested this on simplytest.me by running some requests through a proxy service and reviewing the order of IP addresses shown. Looks good in D7. Code is fine too, patch still applies.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 28175-15-access-log-sort.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Reviewed & tested by the community

test forum pager fail?

thedavidmeister’s picture

15: 28175-15-access-log-sort.patch queued for re-testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 28175-15-access-log-sort.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Needs review

15: 28175-15-access-log-sort.patch queued for re-testing.

David_Rothstein’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 28175-15-access-log-sort.patch, failed testing.

dcam’s picture

Status: Needs work » Needs review

15: 28175-15-access-log-sort.patch queued for re-testing.

dcam’s picture

Re-setting RTBC status after random test failure.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: 28175-15-access-log-sort.patch, failed testing.

amitgoyal’s picture

Status: Needs work » Needs review

15: 28175-15-access-log-sort.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 15: 28175-15-access-log-sort.patch, failed testing.

dcam’s picture

Status: Needs work » Reviewed & tested by the community

Re-setting RTBC status after random test failure.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x - thanks!

  • David_Rothstein committed 71651db on 7.x
    Issue #28175 by dcam, bleen18 | bertboerland: Fixed Ordering by 'Visitor...

Status: Fixed » Closed (fixed)

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