-
Notifications
You must be signed in to change notification settings - Fork 121
[Media Library] Update parameter key for number of items to fetch to be per_page
#14444
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
Conversation
|
|
| private enum ParameterKey { | ||
| static let pageNumber: String = "page" | ||
| static let pageSize: String = "number" | ||
| static let pageSize: String = "per_page" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this, @hafizrahman! I will wait for @hichamboushaba to review this.
I am jumping in as this parameter key change will affect both loadMediaLibrary and loadMediaLibraryFromWordPressSite methods in this MediaRemote file.
The number parameter key is from the following documentation. https://developer.wordpress.com/docs/api/1.2/get/sites/%24site/media/
Please make sure to test the following login cases and update the PR testing instructions accordingly.
- Jetpack
- JCP
- No Jetpack. (Application password)
I am afraid that one of the above cases could be broken/affected by this change.
Nice to have: It would be nice to add a unit test to ensure that the parameter key is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good catch, I tested in WordPress.com console and indeed it wants number. Let me refactor this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 7215568
Good for another review.
|
@hafizrahman just sharing this bug that I identified in Android last week, it's similar to this one, we use the |
|
@hichamboushaba thanks for the ping! I'll have it added here. |
|
Added |
selanthiraiyan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, Hafiz!
b. Jetpack CP site case
Unfortunately, the above case doesn't work. I used Blaze Ads plugin to connect my WPCOM account with the JN site.
While trying to load images from the media library, I end up seeing the following error alert.
To debug this,
I looked into proxyman, and I see that I do receive a success response from the store for the following request.
https://public-api.wordpress.com/wp/v2/sites/1234/media?_fields=id%2Cdate_gmt%2Cslug%2Cmime_type%2Csource_url%2Calt_text%2Cmedia_details%2Ctitle&media_type=image&page=1&per_page=25
I looked into Xcode logs, and I see the following decoding error.
<> Mapping Error: typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [_CodingKey(stringValue: "Index 6", intValue: 6), CodingKeys(stringValue: "media_details", intValue: nil), CodingKeys(stringValue: "sizes", intValue: nil)], debugDescription: "Expected to decode Dictionary<String, Any> but found an array instead.", underlyingError: nil))
This looks like the I tried to replicate this, but I couldn't on a test site that I have right now. It's the EOD for me, but I'll try to take a look at this if needed tomorrow, if it's an issue then it would impact Android as well. |
|
Thanks for taking a look, @hichamboushaba!
I have sent invites to my JN store to both you and @hafizrahman. (To your A8C emails) |
|
Version |
|
Using your site @selanthiraiyan, I can see that an image item has the sizes property empty, and when using the WPCom endpoint, this item is returned as an array instead of an empty object (I think this is something that happens a lot with WordPress, in FluxC we have an old class just to handle similar cases). So, my assumption that
|
|
An update on why this is happening on your site @selanthiraiyan, one of the images in your site is pretty small (4x2 pixels...), when an image is small, WordPress skips generating any other alternative sizes (as they are generally smaller than the original one), so this leads to the empty object. |
selanthiraiyan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋 @hafizrahman I am approving this PR as Hicham's explanation makes sense to me.
Could you please clone this woocommerce/woocommerce-android#12989 for iOS and merge this PR? Thanks!
Sure: #14516 |
|
@hafizrahman The release note for this PR is mentioned under version |
|
@selanthiraiyan good catch, thanks, fixing in #14521 |
Closes: #14432
Description
When logging in with application password, the Media Library only fetches 10 images regardless. From investigating and comparing with Android, the API request in iOS uses
numberparameter.According to the API doc,
numberparameter does not exist and insteadper_pageis needed: https://developer.wordpress.org/rest-api/reference/media/#argumentsAndroid also uses
per_pageand thus do not see this issue:https://github.com/wordpress-mobile/WordPress-FluxC-Android/blob/cc17141a0e910d5b808ba6bbfb4b7d393d3517a0/fluxc/src/main/java/org/wordpress/android/fluxc/network/rest/wpapi/media/BaseWPV2MediaRestClient.kt#L231
This PR updates the parameter to the correct one.
The above should also apply the same for Jetpack CP site.
For full Jetpack site, the parameter
numbershould still be used, and this PR differentiates between the two usage.Reference:
Steps to reproduce
a. No Jetpack case (Application Password)
b. Jetpack CP site case
c. WordPress.com / full Jetpack site case
New: "media_type" fix test
Testing information
I tested this on three type of sites above, on iPhone simulator with iOS 18.
RELEASE-NOTES.txtif necessary.Reviewer (or Author, in the case of optional code reviews):
Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement: