fix: use the proper qualified struct tag as column cache key#14
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a cache collision issue in the column cache by changing the cache key from using just the table name to using a fully qualified type name (package path + type name). This prevents different struct types that map to the same database table from incorrectly sharing cached column definitions.
Key Changes
- Added a new
cacheKey()function that generates cache keys based on the fully qualified type name (PkgPath + Name) - Updated
buildColumns()to use the new type-based cache key instead of the table name - Minor formatting changes to commented-out code for consistency
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c4b18b2 to
f4c800e
Compare
zepatrik
left a comment
There was a problem hiding this comment.
Note: depending on the use-case, you can also use .Select(colNames...). But this caching is really a pita...
If there are additional column names, it won't cache anyways Line 270 in f4c800e |
Yes that's what I wanted to say 😅 |
zepatrik
left a comment
There was a problem hiding this comment.
Nice, now we can have multiple structs for one table 😍
The question remains, is this now actually improving anything, or could we just remove the cache in general?
Well the cache is useful in general, because reflection is somewhat slow, so caching the columns per struct is still nice. |
Right, but now we use reflection to compute the cache key... |
No description provided.