LibrePhotos / librephotos

A self-hosted open source photo management service. This is the repository of the backend.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding ETag support for /api/albums/date/list/ endpoints

savvasdalkitsis opened this issue · comments

Describe the enhancement you'd like
UhuruPhotos currently has a recurring job (by default needing charging) to fetch all the photo summaries of the user's 'feed' using the /api/albums/date/list/ and /api/albums/date/list/{id} endpoints.

The reason for that is that there is no way for the app to know if the user has added media on the server that belong to a much earlier date, therefore a deep sync is needed to make sure the app isn't missing data.

Describe why this will benefit the LibrePhotos

I think adding support for ETags on the above endpoints would allow the clients to perform syncs with minimal overhead

Additional context
https://docs.djangoproject.com/en/5.0/topics/conditional-view-processing/

We use Django Rest Framework, which does not work in the same ways as regular Django views. I researched a bit, but it looks to me like a similar thing is not implemented in the framework itself, but only with third party libraries, which are not maintained.

Your request sounds to me like you want a parameter for last modified for both endpoints.

In order to implement that, we can either add a last_modified_field, which we update on every save of the model, similar to saving EXIF data back, or we can add something like https://github.com/jazzband/django-simple-history to provide a complete history and an option to revert to a previous model state.

Is there a need for having a complete history, or do you think just adding a new parameter to the endpoints and a new field is enough? Do you just need new photos or also updated photos? How do you handle deleted photos?

I would imagine a last updated would work for the main endpoint but not much use in the individual ones since I would need to get them to check the date anyway so at that point I already have the latest version.

The point of the etag is that client libraries automatically support it and the server can skip sending the body (and more importantly skip any dB lookups) if the client already has the latest version. Making the calls much faster