-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve pool navigation/browsing #403
base: master
Are you sure you want to change the base?
Conversation
FROM pool_post pp, | ||
LATERAL get_pool_posts_around(pp.pool_id, pp.post_id) around | ||
WHERE pp.post_id = :post_id; | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use SQLAlchemy instead of writing raw SQL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The search_by_image()
function uses raw SQL only because Postgres' unnest()
function is not implemented in SQLAlchemy. But this query should be able to be written using SQLAlchemy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to also look at how we currently implement GET /post/<ID>/around
as a springboard
@@ -134,14 +135,18 @@ def get_post_content_path(post: model.Post) -> str: | |||
) | |||
|
|||
|
|||
def get_post_thumbnail_path(post: model.Post) -> str: | |||
assert post | |||
def get_post_thumbnail_path_from_id(post_id: int) -> str: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this function is necessary, see below
WHERE pp.post_id = :post_id; | ||
""" | ||
|
||
for order, pool_id, post_id, delta in db.session.execute(dbquery, {"post_id": post.post_id}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using SQLAlchemy, you should just capture the model.Pool
and model.Post
objects directly instead of working with the IDs
posts = dict() | ||
|
||
for pool in db.session.query(model.Pool).filter(model.Pool.pool_id.in_(pool_ids)).all(): | ||
pools[pool.pool_id] = pool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be unnecessary if you let SQLAlchemy fetch the pools directly in the first place, instead of fetching the pool IDs
|
||
for result in db.session.query(model.Post.post_id).filter(model.Post.post_id.in_(post_ids)).all(): | ||
post_id = result[0] | ||
posts[post_id] = { "id": post_id, "thumbnailUrl": get_post_thumbnail_path_from_id(post_id) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be unnecessary if you let SQLAlchemy fetch the posts directly in the first place, instead of fetching the post IDs.
Also, when you do this, the get_post_thumbnail_path_from_id()
won't be needed anymore
model.PoolPost.pool_id, | ||
search_util.create_num_filter, | ||
)(query, criterion, negated) | ||
from szurubooru.search.configs import util as search_util |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already imported at top
@@ -0,0 +1,68 @@ | |||
from alembic_utils.pg_function import PGFunction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is writing a SQL function really necessary instead of doing it in SQLAlchemy? This is something that can get very hard to maintain in the future
Not sure if this is still active but I've added some comments |
Are there any updates on this? Thanks. |
this implementation was *heavily* cherry-picked from PR rr-#403.
Related to #380.
sort:pool
for post searches, which will sort the results by the order defined by thepool:
named token in the same search query.pool:
named token is in the current query.