Skip to content

Conversation

NinoFloris
Copy link
Member

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.

Copy link
Contributor

@vonzshik vonzshik left a comment

Choose a reason for hiding this comment

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

Overall, looks good, just one question.

@NinoFloris NinoFloris enabled auto-merge (squash) September 10, 2024 13:26
@NinoFloris NinoFloris merged commit 6c867d8 into npgsql:main Sep 10, 2024
15 checks passed
NinoFloris added a commit that referenced this pull request Sep 10, 2024
@NinoFloris
Copy link
Member Author

Backported to 8.0.4 via f33567b

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

Successfully merging this pull request may close these issues.

2 participants