User resolver PgTypeInfo reuse #5737
Merged
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.
It's a general cleanup but it relates to #5725
Users inside custom resolvers - where they only have a datatypename of what they want to resolve - are unable to call
options.GetTypeInfo
with a PgTypeId as it would normally expect an Oid to be passed in (PortableTypeIds = false).Somewhat accidentally we haven't exposed the methods that users would need to do so.
Specifically
https://github.com/npgsql/npgsql/compare/main...NinoFloris:pgtypeinfo-reuse?expand=1#diff-afcb93fbb1e1b4b05982008eba6f3ed93423c73714bb73ef569728191f0ac0a5R99-R100
does not do a
GetCanonicalTypeId
call today.The reason originally for leaving out the lookups are that they are not free, while they can be easily overlooked if they happen implicitly. So to make sure we released an implementation in 8.0 without any of those we delegated that task to the caller. However... the methods for callers to do this work were not exposed publicly, leaving users without a way to do so at all.
This PR introduces internal variations of the public methods to make sure we don't regress our lookup code, keeping things explicit internally. The public variants may now do a lookup going forward allowing users to return info coming from other resolvers. Doing so is harmless for perf in a resolver (as their results will be cached).
Next up is the question whether we should expose DatabaseInfo on PgSerializerOptions. Users may need access to it to resolve PgTypeInfo for some plugin type, where the schema of the plugin is not known to the user until database types are loaded at runtime. As DataTypeName expects a fully qualified name users would be stuck. An additional argument would be that users might want to write resolvers that vary their mappings based on database version/features. I'll leave any strong opinion about these arguments in the middle for now, but I won't be against exposing it.