I have a counter table with over 1mln records so probably this is why I am experiencing all the problems. However, I still think that most of the problems could be avoided in one or another way.
Just looking into the code:
Last lines look like:

    if ($counter_show_administer_only && !user_access('administer counter')) {
      return;
    } else {
      return $block;
    }

Please note, if the 'if' statement is true the block returns an empty result but even then it still does all the calculations and executes all database queries. This is clearly a mistake.

I suggest to put this 'if' statement at the beginning of the function to avoid all the costly code executions if the function returns an empty result anyway.

CommentFileSizeAuthor
#2 couter_skip_admin.png17.01 KBdrupalnesia

Comments

kobit’s picture

The same actually applies to showing 'Since:' date. The module first loads the data from database and then checks whether to use to user provided date or the date loaded from the database. In case the user provided the date to use the database request is a waste and impacts performance even though the query results are not actually used at all.

drupalnesia’s picture

StatusFileSize
new17.01 KB

The $counter_show_administer_only is not used for disable counting process. This variable used for HIDE the Counter block, that's why all query still execute.
The variable to SKIP all query for Admin is: $counter_skip_admin.
Look at attached image in this post.

drupalnesia’s picture

6.x-2.3: Bug fix: Performance, add index to counter: counter_date and counter_ip

In my test Counter module performance increase 300%, and only requires < 1 s to execute the slow queries before, as shown below:

-----------------------------------------------------------
0.6 1 SELECT counter_date FROM counter ORDER BY counter_date DESC LIMIT 1
0.77 SELECT count(*) as total FROM (SELECT counter_ip FROM counter GROUP BY counter_ip) c
-----------------------------------------------------------

Please test and report again, thanks.

drupalnesia’s picture

Status: Active » Closed (fixed)

Fixed.