Opened 3 years ago
Closed 3 years ago
#8591 closed enhancement (fixed)
Improve query that runs to find total activities count in spam activity table
Reported by: | oztaser | Owned by: | imath |
---|---|---|---|
Milestone: | 10.0.0 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Activity | Keywords: | has-patch |
Cc: |
Description
An unlimited query is running to find total activities count in the spam activity table and then it causes PHP memory limit error. In our case we have more than 2m activity records.
<?php $count_activities = bp_activity_get( array( 'fields' => 'ids', 'show_hidden' => true, 'count_total' => 'count_query', ) );
Query log:
# There is no need to run this query IMO. SELECT DISTINCT a.id FROM wp_bp_activity a WHERE a.is_spam = 0 AND a.type NOT IN ('activity_comment', 'last_activity') ORDER BY a.date_recorded DESC, a.id DESC # This query runs for finding the total count. SELECT count(DISTINCT a.id) FROM wp_bp_activity a WHERE a.is_spam = 1 AND a.type NOT IN ('last_activity')
Attachments (2)
Change History (7)
#2
@
3 years ago
- Component changed from (not sure) to Activity
- Keywords has-patch added
- Milestone changed from Awaiting Review to 10.0.0
Hi @oztaser
Thanks for your report and patch. Let's look at it during 10.0.0
#3
@
3 years ago
Hi @oztaser
I gave a deeper look to this issue. Even if you set the per_page
attribute to 1, there's an extra query that is run.
In 8591.2.patch, I'm suggesting to introduce a new argument to BP_Activity_Activity::get()
so that it's possible to only get the result of a count query. Could you check it's improving your situation?
Thanks in advance.
I am not sure is it the best way but we can simply pass the
per_page
parameter to function. The other way maybe we can create some function that runs count query grouped byis_spam
.What is your suggestions?
I've prepared a MySQL procedure for creating test data, it may help if you want to create dummy activity records.