Reputation: 101
What does Query.Release()
do behind the scene?
What does that mean 'return query back to pool'?
When Query.Get()
should be used and when Query.GetRelease()
?
Upvotes: 2
Views: 428
Reputation: 21
As you noticed in the docs https://godoc.org/github.com/gocql/gocql#Query. Release it does indeed release the query back into the pool. It should be used when you no longer want to use the particular query in question.
An unreleased query can be reused if you want to make it more performant since you don't need to perform any of the initialization that always happen when a query is created.
Exactly when each should be used is of course up to your case but the general principle is as above. Typically you would put a defer q.Release()
directly after creating the query but it depends on your exact use case.
As for gocqlx.GetRelease()
it does this for you under the hood to allow for a very convenient and safe way to query and get the result without needing to handle the cleanup.
Upvotes: 2