[wp-trac] [WordPress Trac] #50410: Media grid: hiding the "contextually created attachments" breaks the collection length count

WordPress Trac noreply at wordpress.org
Wed Jun 17 14:25:23 UTC 2020


#50410: Media grid: hiding the "contextually created attachments" breaks the
collection length count
---------------------------------------+--------------------
 Reporter:  afercia                    |      Owner:  (none)
     Type:  defect (bug)               |     Status:  new
 Priority:  normal                     |  Milestone:  5.5
Component:  Media                      |    Version:
 Severity:  normal                     |   Keywords:
  Focuses:  accessibility, javascript  |
---------------------------------------+--------------------
 After [41732], [41937], and [42739] the "contextually created attachments"
 are filtered out from the Media grid view.

 "Contextually created attachments" are, for example, the ones created when
 cropping an image for the site logo, site header, etc. In this cases, the
 attachments are marked with a `context` property to distinguish them from
 user-uploaded attachments.

 While I do understand the arguments on the related tickets #21819 and
 #42968, there is a problem with this implementation.

 Actually, the attachments collection is filtered ''after'' it is fetched
 from the server. This breaks the expected collection length, which is
 supposed to be 40 attachments "per page".

 Also, it makes impossible to build logic based on the collection length as
 necessary for #50105 so this issue is a blocker for #50105.

 Additionally, I'm still not fully sure if this impacts also the "per page"
 setting and the collection `hasMore()` built-in method. This would require
 further investigation.

 Basically, filtering the collection "after the fact" (o.e. after it gets
 fetched) artificially alters the model length property which is still 40
 (for example) while the actual attachments displayed may be less than 40.

 Ideally, the filtering should happen when fetching the collection. I do
 realize the attachments context
 [https://core.trac.wordpress.org/ticket/21819#comment:36 is based on a
 not-indexed meta] and querying for that would cause performance issues.
 However, filtering ''after'' the fetch doesn't seem ideal for many
 reasons.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/50410>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list