We're running into an issue on a large online community site and hoping you can help us. When attempting to save a user profile, we receive an error message and the save fails. We have tracked this down to the SQL query that is built in the _activity_log_update_related() function in the activity_log.cache.inc file.

What we are seeing is the function creates an extremely large SQL query with thousands of LIKEs added to the WHERE clause, one for each 'aids'. As an example, here is part of a query we see for uid = 1. I won't copy all of it because it's thousands of lines long:

User warning: Lock wait timeout exceeded; try restarting transaction query: UPDATE activity_log_messages SET cached = '' WHERE (stream_owner_id = 1 AND stream_owner_type = 'user') OR aids LIKE '%,567,%' OR aids LIKE '%,568,%' OR aids LIKE '%,569,%' OR aids LIKE '%,570,%' OR aids LIKE '%,571,%' OR aids LIKE '%,572,%' OR aids LIKE '%,661,%' OR aids LIKE '%,662,%' OR aids LIKE '%,663,%' OR aids LIKE '%,664,%' OR aids LIKE '%,665,%' OR aids LIKE '%,666,%' OR aids LIKE '%,822,%' OR aids LIKE '%,823,%' OR aids LIKE '%,824,%' OR aids LIKE '%,825,%' OR aids LIKE '%,826,%' OR aids LIKE '%,827,%' OR aids LIKE '%,828,%' OR aids LIKE '%,829,%' OR aids LIKE '%,830,%' OR aids LIKE '%,881,%' OR aids LIKE '%,882,%' OR aids LIKE '%,913,%' OR aids LIKE '%,986,%' OR aids LIKE '%,1097,%' OR aids LIKE '%,1098,%' OR aids LIKE '%,1099,%' OR aids LIKE '%,1100,%' OR aids LIKE '%,1627,%' OR aids LIKE '%,1628,%' OR aids LIKE '%,1629,%' OR aids LIKE '%,1630,%' OR aids LIKE '%,1631,%' OR aids LIKE '%,1632,%' OR aids LIKE '%,1633,%' OR aids LIKE '%,1634,%' OR aids LIKE '%,1639,%' OR aids LIKE '%,1640,%' OR aids LIKE '%,1733,%' OR aids LIKE '%,1734,%' OR aids LIKE '%,1735,%' OR aids LIKE '%,1736,%' OR aids LIKE '%,1737,%' OR aids LIKE '%,1738,%' OR aids LIKE '%,1800,%' OR aids LIKE '%,1801,%' OR aids LIKE '%,1802,%' OR aids LIKE '%,1803,%' OR aids LIKE '%,2154,%' OR aids LIKE '%,2299,%' OR aids LIKE '%,2300,%' OR aids LIKE '%,2387,%' OR aids LIKE '%,3001,%' OR aids LIKE '%,3002,%' OR aids LIKE '%,3003,%' OR aids LIKE '%,3004,%' OR 
...
aids LIKE '%,19232,%' OR aids LIKE '%,19233,%' OR aids LIKE '%,19234,%' OR aids LIKE '%,19235,%' OR aids LIKE '%,19236,%' OR aids LIKE '%,19237,%' OR aids LIKE '%,19238,%' OR aids LIKE '%,19239,%' OR aids LIKE '%,19240,%' OR aids LIKE '%,19241,%' OR aids LIKE '%,19242,%' OR aids LIKE '%,19243,%' OR aids LIKE '%,19244,%' OR aids LIKE '%,19245,%' OR aids LIKE '%,19246,%' OR aids LIKE '%,19247,%' OR aids LIKE '%,19248,%' OR aids LIKE '%,19249,%' OR aids LIKE '%,22702,%' OR aids LIKE '%,22703,%' OR aids LIKE '%,26989,%' OR aids LIKE '%,26990,%' OR aids LIKE '%,26991,%' OR aids LIKE '%,26992,%' OR aids LIKE '%,26993,%' OR aids LIKE '%,26994,%' OR aids LIKE '%,26995,%' OR aids LIKE '%,26996,%' OR aids LIKE '%,29080,%' OR aids LIKE '%,29081,%' OR aids LIKE '%,29082,%' OR aids LIKE '%,29083,%' OR aids LIKE '%,29084,%' OR aids LIKE '%,29085,%' in _db_query() (line 169 of /home/www/public_html/includes/database.mysqli.inc).

We have a very high powered database server for this site, but there are so many LIKEs that the query will run for several minutes and still never complete.

We noticed that the need for the LIKEs is due to the multiple reference values stored in the 'aids' column in the activity_log_messages table. We're curious to know, is there a specific reason why the values are loaded into one column? Would it be possible to have a cross reference table between activity_log_events and activity_log messages that stores each record as a separate row? If the values were separated into their own rows in a dedicated table it would eliminate the need for a query with so many LIKEs.

Thanks in advance for your feedback.

Comments

IceCreamYou’s picture

Ouch.

Yes, I'm sure there is a more efficient way to do this. Short-term it is totally okay to comment out the line that causes that query (activity_log.cache.inc line 100) which will just result in old, cached activity records not showing updated user profile information (e.g. a changed profile picture). Properly fixing this will require more time and effort than I have available.