Skip to content
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

API: Add File Attachment & Parent Details to Media Endpoint #20408

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

Aurorum
Copy link
Contributor

@Aurorum Aurorum commented Jul 19, 2021

Required for Automattic/wp-calypso#54691

Changes proposed in this Pull Request:

Adds two pieces of information to the Media endpoint:

  • Details from the "Uploaded to" section (it already exists in WP-Admin, so this is part of the effort for it to mirror Calypso)
  • Details about where the file has been attached

Jetpack product discussion

  • N/A - all in Calypso.

Does this pull request change what data or activity we track or use?

  • I don't think so, this is just a change needed for Calypso

Testing instructions:

  • Add a file from a specific post, and include that file into various other posts
  • Inspect the call to the media endpoint
  • Verify the response includes the correct data relating to this

Screenshot 2021-07-19 at 17 32 57

'post_type' => 'any',
);

$content_query = new WP_Query( $args );
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we use an OR operator instead of doing a query for each file size? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've tried doing some research and testing this, but my understanding is that this doesn't work with the search parameter. I haven't been able to get it to work, so I feel like it might be necessary to do individual queries for each size?

);
}

return $data;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should filter the array by unique URLs. I guess there are cases when both sizes are present in the same post, in which case I think we'll have duplicate entries, right? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, I'll fix that!

@BogdanUngureanu
Copy link
Contributor

@Aurorum, many thanks for the contribution! I've had a look and I've made a few suggestions about the implementation. One thing that I think we could look into is the performance impact. Since we are doing a search in all post types, what if we could make this operation on demand?

For example, what if we change a bit the UI in Calypso and add a button in the UI asking something like "Refresh/Retrieve the occurrences of this media"? When pressed, we'll make an API call that executes that method call and stores the result in the attachment metadata.

I think we could explore this and maybe get some feedback on it from other folks. :) Thanks again for taking the time to look into this. :)

@Aurorum
Copy link
Contributor Author

Aurorum commented Jul 21, 2021

Thanks @BogdanUngureanu! That sounds like a good approach - I've started work on some of it, but I'll need to add the Calypso-side at some point later this week.

@Aurorum
Copy link
Contributor Author

Aurorum commented Jul 23, 2021

Hi @BogdanUngureanu! I'm trying to implement the button you recommended in Calypso, but I'm struggling to understand how to store the media query. Generally, my understanding is it should look something like this:

this.props.requestMedia( this.props.siteId, { query_attached_files: 1 } ).then( ( mediaData ) =>
	this.setState( {
		mediaData,
	} )
);		

Although that successfully makes the API request, it doesn't store the response. Would you have any idea how to do that?

@BogdanUngureanu
Copy link
Contributor

Hi @Aurorum, that looks ok, I think. You could check if the promise is rejected or not, maybe that's why the state is not persisted.

@jeherve jeherve added [Feature] WPCOM API [Pri] Normal [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress labels Aug 3, 2021
@obenland
Copy link
Member

@Aurorum @BogdanUngureanu Any chance you could take another stab at this? Looks like Automattic/wp-calypso#54691 is blocked by its progress

@BogdanUngureanu
Copy link
Contributor

Hi @obenland - sorry for the late response, sure, I think I could work on it in some of my 20% time.

About the Calypso part, I'm not 100% confident about the design, because there are cases when a image would be used in a lot of post types, in which case that list would be huge and might break the modal layout.

@obenland
Copy link
Member

Thank you!

Yeah we could probably limit that list to five posts or something, but that is probably best discussed in the Calypso ticket itself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WPCOM API OSS Citizen This Pull Request was opened by an Open Source contributor. [Pri] Normal [Status] In Progress Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants