-
Notifications
You must be signed in to change notification settings - Fork 13
Update our minimal data logic to be a fallback logic #590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vasconsaurus
wants to merge
13
commits into
main
Choose a base branch
from
6470-6500-centralize-minimal-data-fallbacks-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
04d5876
to
a3c474b
Compare
This is still kind of messy, I just wanted to make sure methods get the expected values for now. But I should clean up the fallback method, and the parse method.
I added a DATA_STRUCTURE constant to define the expected structure of the data hash. This helps as documentation, but we can also initialize with a deep copy of this structure to ensure all keys are present, because some methods rely on the presence of certain keys. I also think fallback and required_fields should be instance methods, and we shouldn't need a separate minimal_data method anymore. But we do need it for get_error_data, since I haven't found a better solution yet, I kept this as a middle ground.
Since this refers to cache, and cache_key, key is clearer.
medias_helper: makes sure we merge error_data media: we only need to return the data we already have, we shouldn't need to set_fallbacks again medias_controller_test: use MediaData.required_fields
Before, when minimal_data was still a method inside Media, it expetected the whole media object. After begin refactored as a method inside MediaData, we can just pass the URL. Note: - test "should return data with error message if can't instantiate" is flaky. And I'm not sure about what it is trying to do. I left it as is for now.
Since we deleted it before we parse, when it got to the archive_if_conditions_are_met method, the options hash never had the :force key. This also reads better.
- A suggestion: I'm matching and getting the new Parser instance, instead of looping. I think this makes it easier to read. - I moved the hashes we create so it is easier to read, but I still don't like it, it doesn't really solve the issues: - why do we have to set the url to parser.url here? - I think the parser should set thr provider and type.
I'm still not a fan of setting provider, type and url inside the parse method separately. But, turns out, we were doing this inside oembed, which I think is worse. So I'm at least moving that out, and we can rethink it.
Not a big fan of the name, but Caio was right all along, and this is not yet a json. So the name is misleading.
For page_item we check if cookies are present, and set original_url as the url if they are. So, we make sure we are actually setting the value, and check for presence before setting it in parse.
- Also sets a minimal data for parser, as we are doing for media – We call get_oembed_data at different points, and since we are not setting everything up front, we now have to deal with items not being present.
c85d3b1
to
d7278b3
Compare
As of recently, failed code climate upload. |
|
Sounds good, @vasconsaurus - @melsawy please review this PR. |
Sure Caio will do today isA |
melsawy
approved these changes
Sep 11, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
We realized we were setting default/fallback values in a way that was a bit scattered around. So we want to centralize this. How I approached it:
At first, we thought about setting defaults, but I decided to treat this as a fallback. The parsers don’t have to worry about checking anything, they can just send back whatever they want. And in the end, we check the response, and add fallbacks where needed.
References: CV2-6500, CV2-6470
How has this been tested?
By running the test suite over and over.
Things to pay attention to during code review
This touches a lot of Media logic, I tried to get it to work, and then tried to clean it up. I think this one requires a lot of attention in general, but here are the main notes:
MediaData
concern. It has a few methods, and a DATA_STRUCTURE constant that defines the expected structure of the data hash.Checklist