Skip to content
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

Eager query method & Clean options for eager loading. #73

Merged
merged 5 commits into from
Apr 25, 2018

Conversation

larrymjordan
Copy link
Member

Hi @markbates this solves issue #72

Clean eager fields slice after every SQL command execution
@larrymjordan larrymjordan requested a review from markbates April 20, 2018 20:53
connection.go Outdated
@@ -182,6 +182,12 @@ func (c *Connection) Q() *Query {
return Q(c)
}

// eagerDisabled disables eager mode for current connection.
func (c *Connection) eagerDisabled() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@larrymjordan should this be called something like "disableEager" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paganotoni yes, that makes sense.

@markbates markbates requested a review from stanislas-m April 20, 2018 21:00
stanislas-m
stanislas-m previously approved these changes Apr 21, 2018
Copy link
Member

@stanislas-m stanislas-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fast fix, that's awesome! I just tested the changes, and my problems are solved. 👍

I'm just a bit curious about this specific use-case: if I use the same connection in two or more goroutines in parallel (let's say I want to use eager creation in these goroutines), does it work? As I understand the way it works, if an eager creation finishes just before a parallel creation goes to check the eager flag, the eager mode will be disabled for the second goroutine.

@markbates
Copy link
Member

@stanislas-m @larrymjordan I'm also concerned about storing "state" information on the connection. How do we solve this problem? Is this PR safe to merge, while a solution is found? or should this PR wait? You both know more on the subject than I do so I'm going to trust you two. :)

@stanislas-m
Copy link
Member

stanislas-m commented Apr 22, 2018

@markbates @larrymjordan Well, if the eager options on connection are used just for querying, how about removing them from the Connection? I'm not sure about that, but it seems to be the safest solution here, if it's possible.

Using Eager() on a Connection probably should return a new *Query instead of the *Connection. This way, the eager feature is isolated per query. Again, this suppose it won't impact the eager creation, and I'm not sure about that.

Edit: Eager creation seems using the eager attributes at a connection level. So, how about cloning the connection when using Eager() on a Connection? This way, it can be isolated properly.

@markbates
Copy link
Member

My first reaction was copying transaction too. But I think returning a query is better, but it’s a breaking change.

I think what someone really needs to do is write up an issue describing how this feature should work, including different use cases, etc…

@larrymjordan
Copy link
Member Author

@markbates @stanislas-m The reason why Eager function is attached to Connection is because of the executors Create, ValidateAndCreate methods. The only way to access these methods is through Connection object. So the way I handled that to be able to introduce Eager creation was by adding those states to Connection. By returning a query with eager how can we use it for eager Creation? Any ideas?

@stanislas-m
Copy link
Member

@larrymjordan As I proposed, I think for Create and ValidateAndCreate we can create a copy of the Connection. This way, the eager feature is isolated from other requests.

@larrymjordan
Copy link
Member Author

@stanislas-m can you take a look when you have the chance to my last commit, is that what you suggested?

@stanislas-m stanislas-m dismissed their stale review April 25, 2018 17:35

Need to test the changes

@stanislas-m
Copy link
Member

@larrymjordan Sure, I'll take a look in a few minutes.

Copy link
Member

@stanislas-m stanislas-m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me. 👍

@markbates markbates merged commit d02695e into gobuffalo:master Apr 25, 2018
@markbates
Copy link
Member

@larrymjordan @stanislas-m great work!!

@trevrosen
Copy link
Contributor

@larrymjordan @stanislas-m just ran into the underlying bug -- thanks so much for taking the time to produce a fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants