Was playing with
MDL-14257 when I saw some things that could be slightly improved in the add_to_log() current incarnation:
1) The update of lastip and lastaccess (user table): The query es executed ALWAYS, no matter if it finally ends updating the record or no. Proposal: perform the ( $timenow - lastaccess > 60) condition in PHP (using the $USER->lastaccess) variable. And, of course updating it if the record is updated.
2) The update of timeaccess (user_lastaccess table): We always perform one query + one update, no matter if the update finally changes anything or no. Proposal: Fetch also the timeaccess in the query and then perform the ($timenow - timeaccess > 60) condition in PHP.
That way we'll save TWO updates per add_to_log() call, that is, indeed, a lot!
My only concern is about to update $USER->lastaccess continuosly. Not sure if if affects recent activity and so (I guess no and lastlogin is used instead). But better to confirm it.
PS: Feel free to reassign to me if you think it's ok and you want me to implement.