-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip references if sql EXPLAIN passes
Currently, there are a lot of factors that determine whether or not a query can be executed without the `.references` call. ActiveRecord itself is even smart enough to figured it out and add it for you if you use the hash `.where` syntax: ContainerImage.includes(:containers => {}) .where(:containers => {:name => "foo"}) .to_sql So as a fail safe, if `skip` is passed to method `Rbac::Filterer#include_references`, then we can do an much cheaper explain to figure out if it is a valid query before deciding if skipping is a bad idea. This means 1 extra query to every RBac call search that is currently "skippable" by our criteria, but they should hopefully be quick to execute and be a fail safe for what we miss. Note, doing a `scope.explain` will both execute the regular query and the explain, and since we have a lot of heavy Rbac calls, this would not be ideal. We work around this by calling a private API with `.to_sql` to only execute the EXPLAIN query, which still returns an error of `ActiveRecord::StatementInvalid` when it is malformed. In that same vain, a check if we are in a transaction is also required, and setting up a transaction SAVEPOINT is necessary so we don't pollute the transaction in the process. More info on that here: https://stackoverflow.com/a/31146267/3574689
- Loading branch information
1 parent
2a1e0e1
commit 3f4d50e
Showing
2 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters