Skip to content

Fetch already published schemas by Subject and Version (or latest)#8

Open
tak30 wants to merge 4 commits intoklarna:masterfrom
tak30:feature/get_published_schemas
Open

Fetch already published schemas by Subject and Version (or latest)#8
tak30 wants to merge 4 commits intoklarna:masterfrom
tak30:feature/get_published_schemas

Conversation

@tak30
Copy link
Copy Markdown

@tak30 tak30 commented Sep 11, 2019

Sometimes there is a need to download an already published schema by Subject and Version.
I didn't add the schemas to the local cache as, as far as I understand, in this use case the user of the library should be the one taking care of how to use the schema.

Copy link
Copy Markdown

@k32 k32 left a comment

Choose a reason for hiding this comment

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

Hello,

Thanks for the PR, looks like this feature is missing. But perhaps it should be implemented as part of maybe_download/1 function.

get_schema(Subject) ->
get_schema(Subject, "latest").

get_schema(Subject, Version) when is_integer(Version)->
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Coding style: extra space before when and missing space before ->

Copy link
Copy Markdown
Author

@tak30 tak30 Sep 12, 2019

Choose a reason for hiding this comment

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

Done!

Fixed code style and other bugs after code review.
@tak30
Copy link
Copy Markdown
Author

tak30 commented Sep 12, 2019

Hello,

Thanks for the PR, looks like this feature is missing. But perhaps it should be implemented as part of maybe_download/1 function.

Hello, thanks for reviewing!
As far as I understand maybe_download/1 retrieves a decoded schema by either SchemaId or SubjectName and Fingerprint.

In my use case, as I didn't register the schema, I don't know the schemaId or the Fingerprint. I do believe that this use case is out of the main flow supported by this library so it should be an independent function, as it's just an extra.
What do you think?

Copy link
Copy Markdown
Contributor

@zmstone zmstone left a comment

Choose a reason for hiding this comment

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

Why not cache it, if the caller of this new API can benefit from having it cached.
e.g. so it can crash then restart without having to re-download.

The cache key is currently either regid() or {Subject, FP}.
We can expand the cache key to support {Subject, Version}
however, the current patterns are

-define(IS_REGID(Id), is_integer(Id)).
-define(IS_NAME_FP(NF), (is_tuple(Ref) andalso size(Ref) =:= 2)).
-define(IS_REF(Ref), (?IS_REGID(Ref) orelse ?IS_NAME_FP(Ref))).

I guess we'll have to add a tuple of size 3 for this new cache.

{ok, #{<<"schema">> := Schema, <<"id">> := Id}} ->
{ok, Id, Schema};
Error ->
{error, Error}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just Error to return here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

sure

URL = RegistryURL ++ "/subjects/" ++ Subject ++ "/versions/" ++ Version,
case httpc_download(URL) of
{ok, #{<<"schema">> := Schema, <<"id">> := Id}} ->
{ok, Id, Schema};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it's more useful to decode it to regid() (change the type spec also).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good one

@tak30
Copy link
Copy Markdown
Author

tak30 commented Sep 12, 2019

Why not cache it, if the caller of this new API can benefit from having it cached.
e.g. so it can crash then restart without having to re-download.

The cache key is currently either regid() or {Subject, FP}.
We can expand the cache key to support {Subject, Version}
however, the current patterns are

-define(IS_REGID(Id), is_integer(Id)).
-define(IS_NAME_FP(NF), (is_tuple(Ref) andalso size(Ref) =:= 2)).
-define(IS_REF(Ref), (?IS_REGID(Ref) orelse ?IS_NAME_FP(Ref))).

I guess we'll have to add a tuple of size 3 for this new cache.

If you guys believe this flow should be part of the app then yes, let's make the proposed changes. I'll take care of it.

@k32
Copy link
Copy Markdown

k32 commented Sep 17, 2019

Sorry for late reply. zmstone is right about caching. Other interfaces of this library imply that caching is present, so it's good to keep everything consistent.

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Jan 21, 2021

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Pablo López Viqueira seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants