How to Filter a Subquery in Ransack Without Affecting Performance? #1524
              
                Unanswered
              
          
                  
                    
                      migueloporto
                    
                  
                
                  asked this question in
                Q&A
              
            Replies: 0 comments
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I am using the Ransack gem to perform filters in my application, and I have a specific issue with a ransacker that uses a subquery. The problem is that Ransack is appending = TRUE to the generated query, which is negatively impacting performance.
Here is the ransacker code that I am using in the Job model:
And here is the JSON I am using to apply the filter:
When I run the query with Employee.ransack(job_parsed_fq).result.select(:id).to_sql, I get the following SQL:
As you can see, Ransack is appending = TRUE at the end of the subquery, which is causing performance issues.
I have tried various predicates without success. Is there a way to prevent Ransack from adding = TRUE at the end of the subquery? I am looking for a solution that allows me to apply the filter without negatively impacting the query's performance.
Any help or advice would be greatly appreciated.
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions