Does this gem recognize a find on a column without index?
Opened this issue · 4 comments
From having a brief glance at the code, it seems like the gem doesn't analyze calls to #find
and #find_by_<attribute>
, but I might have missed something.
It would be really valuable to check, whether all those calls have an appropriate DB index on the corresponding column.
This would indeed be a great feature! Please point me in the direction of how you think this should be implemented. Is it using some AST
parser?
Yes, I guess you would need to parse the whole source code for that. Before you start implementing that yourself, it might be worth to investigate, whether this would be easier to implement as an additional cop for Rubocop. Rubocop already parses everything, but I don't know, whether it is able to then compare the currently parsed file against the indexes from the schema.rb
.
Thank you for the suggestion, @mak-dunkelziffer! I will look into that.
BTW, would you like to contribute?
Not related to the topic, but since we are talking about AST here. It would be nice to have it as a part of DatabaseConsistency because we would finally be able to write autocorrections for checkers that requires model code changes.
Also, some cool GitHub Action would be possible that can point you to the line where you missed validation.