svthalia / concrexit

Thalia Website built on Django.
https://thalia.nu
Other
23 stars 12 forks source link

Preserve order of uploaded photos #2843

Closed DeD1rk closed 1 year ago

DeD1rk commented 1 year ago

Is your feature request related to a problem? Please describe.

Since filepond, uploaded photos are ordered 'randomly'. (Says tim reijneveld)

Describe the solution you'd like

Photos are ordered according to the name (?) of the uploaded files.

Motivation

Sometimes a certain ordering makes sense within an album.

JobDoesburg commented 1 year ago

Looking at the code, it seems like photos are ordered based on their filename in the zip that is uploaded. So this shouldn't be a problem I think... We could also take a look at EXIF data if we want.

DeD1rk commented 1 year ago

Stijn just texted me about it. Looks like the ordering in the admin makes sense somehow but it's a frontend thing?

DeD1rk commented 1 year ago

Specifically, image number 16 of wine tasting (the cover) is filename 0045.

DeD1rk commented 1 year ago

I don't understand at all but on production it still goes wrong, even for new albums: https://thalia.nu/members/photos/parents-day/

DeD1rk commented 1 year ago

It seems to go wrong when multiple people have liked different photos. For example on https://staging.thalia.nu/api/v2/photos/albums/2023-03-15-test/ (with multiple likes on some photos), but not on https://staging.thalia.nu/api/v2/photos/albums/test-on-docker/ (where currently only I liked some photos). Going to try on localhost (sqlite) now if I can reproduce, and if adding an explicit order_by to each annotated queryset works.

DeD1rk commented 1 year ago

Can't reproduce with sqlite3, but on staging:

>>> a.photo_set.all()
<QueryablePropertiesQuerySet [<Photo: 0000.jpg>, <Photo: 0001.jpg>, <Photo: 0002.jpg>, <Photo: 0003.jpg>, <Photo: 0004.jpg>, <Photo: 0005.jpg>, <Photo: 0006.jpg>, <Photo: 0007.jpg>, <Photo: 0008.jpg>, <Photo: 0009.jpg>, <Photo: 0010.jpg>, <Photo: 0011.jpg>, <Photo: 0012.jpg>, <Photo: 0013.jpg>, <Photo: 0014.jpg>, <Photo: 0015.jpg>, <Photo: 0016.jpg>, <Photo: 0017.jpg>, <Photo: 0018.jpg>, <Photo: 0019.jpg>, '...(remaining elements truncated)...']>
>>> a.photo_set.select_properties("num_likes").all()
<QueryablePropertiesQuerySet [<Photo: 0044.jpg>, <Photo: 0022.jpg>, <Photo: 0018.jpg>, <Photo: 0046.jpg>, <Photo: 0015.jpg>, <Photo: 0042.jpg>, <Photo: 0014.jpg>, <Photo: 0006.jpg>, <Photo: 0004.jpg>, <Photo: 0031.jpg>, <Photo: 0040.jpg>, <Photo: 0020.jpg>, <Photo: 0007.jpg>, <Photo: 0048.jpg>, <Photo: 0026.jpg>, <Photo: 0021.jpg>, <Photo: 0011.jpg>, <Photo: 0001.jpg>, <Photo: 0036.jpg>, <Photo: 0025.jpg>, '...(remaining elements truncated)...']>
>>> a.photo_set.select_properties("num_likes").order_by("pk")
<QueryablePropertiesQuerySet [<Photo: 0000.jpg>, <Photo: 0001.jpg>, <Photo: 0002.jpg>, <Photo: 0003.jpg>, <Photo: 0004.jpg>, <Photo: 0005.jpg>, <Photo: 0006.jpg>, <Photo: 0007.jpg>, <Photo: 0008.jpg>, <Photo: 0009.jpg>, <Photo: 0010.jpg>, <Photo: 0011.jpg>, <Photo: 0012.jpg>, <Photo: 0013.jpg>, <Photo: 0014.jpg>, <Photo: 0015.jpg>, <Photo: 0016.jpg>, <Photo: 0017.jpg>, <Photo: 0018.jpg>, <Photo: 0019.jpg>, '...(remaining elements truncated)...']>

So it seems that select_properties may drop the order in postgres. Adding an order_by again fixes it though.

JobDoesburg commented 1 year ago

select_properties does a whole lot of transformations, so yes, it does drop the order

DeD1rk commented 1 year ago

Should actually be fixed in #2985.