FXIOS-15132 - Merino Rust client cleanup#7274
FXIOS-15132 - Merino Rust client cleanup#7274adudenamedruby wants to merge 9 commits intomozilla:mainfrom
Conversation
a307ee0 to
5138f4f
Compare
mhammond
left a comment
There was a problem hiding this comment.
A bit of a drive-by that initially mis-understood the scope and that this was just a refactor - it's probably worth what it cost you, but I'm hitting "submit" anyway :)
| /// | ||
| /// Each field corresponds to a content category or special feed type. Fields are | ||
| /// `None` when the category was not requested or has no content available. | ||
| #[derive(Debug, Deserialize, PartialEq, uniffi::Record, Serialize)] |
There was a problem hiding this comment.
eek: I just noticed that you did not actually introduce this, just refactored it. So feel free to ignore this entirely, but I'll leave it here as I think it still makes some points worth considering for your future endeavours :)
It's worth being careful deriving both uniffi::Record and serde traits on the same object. The issue is that you are making it such that a change in the "wire" protocol must end up being a breaking change for the mobile clients - this is probably worse for Serialize, and I suspect you don't actually need serialize here - I guess you only deserialize them? But a non-optional field addition (or even deletion!) ends up being seen by the ultimate consumer.
It also means decisions made a long way from the mobile clients ends up deciding the api exposed to these mobile clients - what makes perfect sense for the server code crafting the JSON responses might seem really odd represented as Swift.
Or to make the same point even stronger - what value are these structs providing to the mobile clients? Why not just send them the raw JSON and let them deserialize it?
There was a problem hiding this comment.
Yeah, this is beyond me, honestly, as I don't much know the workings of Uniffi, and just making most of this refactor was really stretching my Rust knowledge lolololo. I think I'll leave this for now, it seems you're ok with that.
As for the bigger point you're making: "what value are these structs providing to the mobile clients? Why not just send them the raw JSON and let them deserialize it?" Ultimately, if we're passing raw JSON, then what would be the purpose of this client, because it's basically just a network call with extra steps. The original reasoning for implementing it was that, ideally, it acts as a singular interface to Merino that provides objects for the clients to use so that each client isn't manually maintaining its own Merino client - that's three times the work to implement any changes and maintenance vs the one. What the clients do with the objects/data afterwards, that makes sense to be on the clients, because they each handle that info differently.
There was a problem hiding this comment.
Ultimately, if we're passing raw JSON, then what would be the purpose of this client, because it's basically just a network call with extra steps.
Exactly 😅
that's three times the work to implement any changes and maintenance vs the one
It's not immediately clear we have achieved that in practice - with this model, some changes will still require touching all 3 consumers of this crate - eg, adding a new field to a struct is technically a breaking change, but adding a new field to a json payload need not be.
If a Rust component is literally a wrapper around JSON and trivial network calls, and has no "difficult" logic or anything else (which is where the real burden of multiple impls come from), then yeah, it really shouldn't be in Rust imo. This single shared impl has a real cognitive burden - the author needs to understand uniffi, have at least a passing knowledge of all binding languages expected to be used (eg, kotlin and swift), and know Rust. A trivial JSON/network component written in, say, just swift is far more approachable to far more people.
(But as above, I know you didn't create this, so it's a meta comment rather than anything about this patch)
There was a problem hiding this comment.
I'll leave this for posterity but there are planned reasons which account for the existence of this component (certain filtering to be done per platform, implementing some sort of cache for this information for more effective retrieval/usage, etc), because otherwise, I'm onboard with you re: this shouldn't just be a middle-man. Those reasons haven't been implemented yet because a) priorities have kept changing and b) because iOS is currently the only consumer of this component. This is about to change, where Android will be switching over to this.
Another reason this was done is that iOS doesn't have a network stack, currently, and any non-webkit things are done pretty haphazardly by setting up individual network calls - which we really shouldn't do if we want to be smart about our architecture.... but nearly all network things we do that are not webkit related, are AS related, so the decision was made to, instead of investing in a network stack on iOS, to streamline things through AS because, as more platfroms used those components, it just made more sense.
42bf612 to
6c691a3
Compare
Co-authored-by: JR Conlin <src+github@jrconlin.com>
The pull request has been modified, dismissing previous reviews.
|
Heya'll, is there anything else you think I need to do on this PR to get it approved & merged? Just trying to get it on it's merry way! :D |
c540272 to
55c0414
Compare
55c0414 to
10df505
Compare
As part of the work to update the Merino Rust client to fetch categories, this first PR does some prep work to make the updates easier, and to improve maintainability for the client.
The commits for this PR are fairly self explanatory for review, but, in general, the PR:
I've successfully tested the changes in the PR:
I don't think this PR needs a CHANGELOG, because it's simply a refactor, not really adding/removing feature or capabilities to the client.
Please note: I am a Rust noob, so please let me know what improvements I can make.
Pull Request checklist
[ci full]to the PR title.