@@ -209,46 +209,15 @@ export const buildQuery = ({
209209 ` . trim ( )
210210 }
211211
212- // Check if filters are safe for activityCount optimization
213- const hasSafeFilters = ( ( ) => {
214- if ( ! filterString || filterString . trim ( ) === '' || filterString . match ( / ^ \s * 1 \s * = \s * 1 \s * $ / ) ) {
215- return true // No filters or trivial filters
216- }
217-
218- // Allow filters that are likely to have good correlation with activity or are very selective
219- const safePatterns = [
220- / \b m \. i d \s * [ = I N ] / i, // ID filters are always safe
221- / \( 1 \s * = \s * 1 \) / , // Trivial conditions
222- / A N D \s * \( 1 \s * = \s * 1 \) / , // Trivial AND conditions
223- / \( 1 \s * = \s * 1 \) \s * A N D / , // Trivial conditions at start
224- ]
225-
226- // Check if filter contains only safe patterns and basic logical operators
227- let cleanFilter = filterString
228- safePatterns . forEach ( ( pattern ) => {
229- cleanFilter = cleanFilter . replace ( pattern , '' )
230- } )
231-
232- // Remove whitespace, parentheses, and basic logical operators
233- cleanFilter = cleanFilter . replace ( / [ \s ( ) ] / g, '' ) . replace ( / \b ( a n d | o r ) \b / gi, '' )
234-
235- // If nothing significant remains, it's safe
236- return cleanFilter . length === 0
237- } ) ( )
238-
239212 // Use activityCount optimization if:
240213 // 1. We have aggregates and are sorting by activityCount
241- // 2. No unsafe joins needed (me.*, mo.* filters)
242- // 3. Filters are safe (mostly ID-based or trivial )
214+ // 2. No expensive joins needed (me.*, mo.* filters)
215+ // 3. Only m.* filters (we can handle these in the CTE )
243216 const useActivityCountOptimized =
244- withAggregates &&
245- ( ! sortField || sortField === 'activityCount' ) &&
246- ! filterHasMe &&
247- ! filterHasMo &&
248- hasSafeFilters
217+ withAggregates && ( ! sortField || sortField === 'activityCount' ) && ! filterHasMe && ! filterHasMo
249218
250219 log . info (
251- `useActivityCountOptimized=${ useActivityCountOptimized } , filterHasMe=${ filterHasMe } , filterHasMo=${ filterHasMo } , filterHasM=${ filterHasM } , hasSafeFilters= ${ hasSafeFilters } ` ,
220+ `useActivityCountOptimized=${ useActivityCountOptimized } , filterHasMe=${ filterHasMe } , filterHasMo=${ filterHasMo } , filterHasM=${ filterHasM } ` ,
252221 )
253222
254223 if ( useActivityCountOptimized ) {
0 commit comments