You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Method chaining corrupts data due to the fact that search.clone() doesn't actually copy its slices.
The first time that you call Where, whereConditions goes from a nil slice to a new slice with length=1, capacity=1.
The second time that you call Where, whereConditions goes from a slice with length=1, capacity=1 to a new slice with length=2, capacity=2.
The third time that you call Where, whereConditions goes from a slice with length=2, capacity=2 to a new slice with length=3, capacity=4. It is here that Go's slice creation has allocated more capacity than we are using.
The fourth time that you call Where, whereConditions remains the same; its length merely grows to 4 and the fourth element is set.
If you used the first 3 Where calls to create a template query, and then if you create two queries that each perform one more Where independently of each other, then the results will be corrupt.
Here's a simple test case to show that this is what's happening. It starts creates a "base" query with 1, 2, 3, and then 4 initial Where calls, and then it creates two additional queries that each use that base to perform a single additional Where call.
In all cases, the text THING1 should only be present in query q1, and THING2 should only be present in query q2. However, this is not the case when w=3, meaning that the base query has 3 Where calls to start with.
Method chaining corrupts data due to the fact that
search.clone()
doesn't actually copy its slices.The first time that you call
Where
,whereConditions
goes from anil
slice to a new slice with length=1, capacity=1.The second time that you call
Where
,whereConditions
goes from a slice with length=1, capacity=1 to a new slice with length=2, capacity=2.The third time that you call
Where
,whereConditions
goes from a slice with length=2, capacity=2 to a new slice with length=3, capacity=4. It is here that Go's slice creation has allocated more capacity than we are using.The fourth time that you call
Where
,whereConditions
remains the same; its length merely grows to 4 and the fourth element is set.If you used the first 3
Where
calls to create a template query, and then if you create two queries that each perform one moreWhere
independently of each other, then the results will be corrupt.Here's a simple test case to show that this is what's happening. It starts creates a "base" query with 1, 2, 3, and then 4 initial
Where
calls, and then it creates two additional queries that each use that base to perform a single additionalWhere
call.In all cases, the text
THING1
should only be present in queryq1
, andTHING2
should only be present in queryq2
. However, this is not the case whenw=3
, meaning that the base query has 3Where
calls to start with.I plan to submit a PR to address this sometime soon.
The text was updated successfully, but these errors were encountered: