Hi,

There is a "bug" in advanced_profile.module.

The latest profile visitors block uses a query that filters users whose access logs contain a path to the current user :
SELECT DISTINCT a.uid, u.name FROM {accesslog} a INNER JOIN {users} u ON a.uid = u.uid WHERE a.uid <> %d AND a.uid > 0 AND a.path LIKE 'user/%d%%' ORDER BY a.timestamp DESC;
The result is stripped down to the 1000 first rows.

This query means that you select the last displays of a page which path is "user/*".
It is wrong because if your uid is 1, the block will display these visits :
- user/150
- user/1290/edit
- user/11

The query should be replaced with :
SELECT DISTINCT a.uid, u.name FROM {accesslog} a INNER JOIN {users} u ON a.uid = u.uid WHERE a.uid <> %d AND a.uid > 0 AND a.path = 'user/%d' ORDER BY a.timestamp DESC;

Comments

artscoop’s picture

There is also a performance hit using the visitors block.
The query is very expensive (320ms on my server), and can be cached :

In advanced_profile.module, go to line 225 (approx.)
Replace
$result = db_query_range($sql, $uid, $uid, 0, 1000);
With

	$result = cache_get('visit'.$uid,'cache_filter');
	if (!$result) {
		$result = db_query_range($sql, $uid, $uid, 0, 100);
		cache_set('visit'.$uid,$result,'cache_filter');
	}

As I use the 'cache_filter' table, I think the cache is cleared periodically (every cron run).

michelle’s picture

Thanks for the report. I'll take a look at it next time I work on APK.

Michelle

michelle’s picture

Status: Active » Needs work

I implemented the first fix and that works, thanks!

The caching, however, gives me this error:

warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result, object given in /home/shellmul/shellsn.com/includes/database.mysqli.inc on line 144.

Michelle

michelle’s picture

Status: Needs work » Fixed

Well, I added the first part and no answer on the caching. I'm actually going to recommend people use the User Visits module instead if they need anything more advanced. The one built into APK is meant to be pretty simple and better for lower traffic sites.

Michelle

Status: Fixed » Closed (fixed)

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