I've spent some time trying to refactor this to consolidate the bits of the sql query that get unioned into one query--each sub section that's unioned is basically identical but for one factor (e.g. all of this stuff + assignee = person, all of this stuff + owner = person). I'm pretty sure it would be more efficient to do "all of this stuff + (assignee = person OR owner = person)" but getting to the point where we can generate that query is a big refactor. I've spent a week off and on looking at it and just keep finding new rabbit holes, so I'm throwing it back in the pot for someone else to take a look at.
I've spent some time trying to refactor this to consolidate the bits of the sql query that get unioned into one query--each sub section that's unioned is basically identical but for one factor (e.g. all of this stuff + assignee = person, all of this stuff + owner = person). I'm pretty sure it would be more efficient to do "all of this stuff + (assignee = person OR owner = person)" but getting to the point where we can generate that query is a big refactor. I've spent a week off and on looking at it and just keep finding new rabbit holes, so I'm throwing it back in the pot for someone else to take a look at.