gallery.accords-library.com/server/szurubooru
rr- 06ab98fa70 server/search: fix sort:random breaking tags
Using sqlalchemy's subqueryload to fetch tags works like this:

1. Get basic info about posts with query X
2. Copy query X
3. SELECT all tags WHERE post_id IN (SELECT post_ids FROM query X)
4. Associate the resulting tags with the posts

When original query contains .order_by(func.random()), it looks like
this:

1. SELECT post.* FROM post ORDER BY random() LIMIT 10
2. Copy "ORDER BY random() LIMIT 10"
3. SELECT tag.* FROM tag WHERE tag.post_id IN (
       SELECT id FROM post ORDER BY random() LIMIT 10)
4. Disaster! Each post now has completely arbitrary tags!

To circumvent this, we replace eager loading with lazy loading. This
generates one extra query for each result row, but it has no chance of
producing such anomalies. This behavior is activated only for
queries containing "sort:random" and derivatives so it shouldn't hit
performance too much.
2016-08-27 01:21:59 +02:00
..
api server/posts: defer flush; save content lazily 2016-08-26 15:09:08 +02:00
db server/general: disable autoflush 2016-08-26 14:41:05 +02:00
func server/posts: defer flush; save content lazily 2016-08-26 15:09:08 +02:00
middleware server/db: make query counter thread-local 2016-08-24 12:31:55 +02:00
migrations server/snapshots: rewrite 2016-08-16 21:51:25 +02:00
rest server/rest: urldecode incoming paths 2016-08-16 21:42:11 +02:00
search server/search: fix sort:random breaking tags 2016-08-27 01:21:59 +02:00
tests server/search: add content-checksum 2016-08-26 16:26:06 +02:00
__init__.py split files into client/ and server/ 2016-04-01 18:48:16 +02:00
config.py server/general: embrace most of PEP8 2016-08-14 16:44:03 +02:00
errors.py server/general: embrace most of PEP8 2016-08-14 16:44:03 +02:00
facade.py server/db: allow full DSN; use memdb in tests 2016-08-16 21:42:09 +02:00