-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Performance improvements and various fixes #4
Open
gencer
wants to merge
5
commits into
umbrellio:master
Choose a base branch
from
gencer:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
With this small change, we will almost instantly filter classes and tear down to the Sequel level. This allow us to only `select()` Sequel models instead of the whole Rails workspace. Thus, we do not need to cache the variable. Because, Rails uses eager load or may use threaded model. This means, when this method fired, only few models would be loaded at that time. This will lead missing models for tables. Note that we also used `c.implicit_table_name`. This is necesary for who uses (like us) multiple Sequel Databases at the same time on single Rails App. `DBModel::TableModel.klazz` will require `implicit_table_name` to demodulize, undersrcore and proper pluralization.
Sequel can send `drop` on commit by default. This can be activated via `on_commit: :drop`. This will minimize queries sent to the Server.
We do not need `self.` calls here. They are redundant.
We also added an exception handling here. Problem here is that, when trigger executed and temporary table does not exists (for example we forgot to send :bulk_audit commands) then there is a issue raises. In this case, if anything goes wrong and transaction is not found, whole object will return immediately without breaking anything.
It seems your tests didn't liked this...
👌 Tests have passed! |
@@ -12,22 +12,21 @@ def self.apply(model, opts={}) | |||
|
|||
module SharedMethods | |||
def model_to_table_map | |||
@@model_to_table_map ||= ObjectSpace.each_object(Class).select do |klazz| | |||
ObjectSpace.each_object(Sequel::Model::ClassMethods).select do |klazz| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sequel::Plugins::BulkAudit::ClassMethods
can be even better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case do we need to check if Model has BulkAudit in next line?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've tried to be more descriptive as possible. Please see the commit description for why and how this fixes applied.
This PR includes:
ObjectSpace
toSequel::Model::ClassMethods
only.drop on commit
while creating temporary tables. This will saves redundant SQL query from sending to the server.Please review and comment for the changes if you think there might be a different changes made.
This fixes #3.