LibrePhotos / librephotos

A self-hosted open source photo management service. This is the repository of the backend.
MIT License
7.01k stars 309 forks source link

Convert raw SQL queries to Django ORM #874

Open sickelap opened 1 year ago

sickelap commented 1 year ago

Convert all raw SQL queries in backend to Django ORM, so we could be database agnostic. There are some queries that are not portable to SQLite3, e.g., some jsonb_* functions. Ideally, this would be done with some form of translation layer to shield the framework from the application, but that's too big of a scope I think.

derneuere commented 1 year ago

Just a heads-up, most of these queries improved the performance. It would be nice if that could stay that way when we switch to ORM.

https://github.com/LibrePhotos/librephotos/pull/499 https://github.com/LibrePhotos/librephotos/pull/193

If I missed a relevant query, it should be easy to figure out the context with git blame :)

spcx86 commented 1 year ago

I am willing to take this up. Looks like this would be a big PR. We can start with an initial PR with one or 2 queries changed to ORM and test and compare the performance(using silk) . How does it sound to you @derneuere ?

derneuere commented 1 year ago

Sounds like a good approach! Please test big datasets and try to coordinate your work with @sickelap. I think he also wants to work on those queries :)