Skip to content
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

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

Ruin0x11
Copy link
Contributor

@Ruin0x11 Ruin0x11 commented May 9, 2021

Related to #380.

  1. Implements sort:pool for post searches, which will sort the results by the order defined by the pool: named token in the same search query.
  2. Modifies the previous/next post order for the post view if a pool: named token is in the current query.
  3. Adds a grid-based view for the pools list page, showing up to the first three posts in each pool.
    1
  4. Implements pool navigators. They allow navigating to the first/last/next/previous post in each pool the post belongs to. The current pool active in the search query will get bolded/placed at the top.
    2

FROM pool_post pp,
LATERAL get_pool_posts_around(pp.pool_id, pp.post_id) around
WHERE pp.post_id = :post_id;
"""
Copy link
Collaborator

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.

Copy link
Collaborator

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

Copy link
Collaborator

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:
Copy link
Collaborator

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}):
Copy link
Collaborator

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
Copy link
Collaborator

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) }
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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

@sgsunder
Copy link
Collaborator

Not sure if this is still active but I've added some comments

@sgsunder sgsunder added the needs-revision This PR needs edits label Sep 24, 2021
@parallax4
Copy link

Are there any updates on this? Thanks.

noirscape added a commit to noirscape/szurubooru that referenced this pull request Jan 4, 2023
this implementation was *heavily* cherry-picked from PR rr-#403.
@acctfpn
Copy link

acctfpn commented Dec 16, 2023

@neobooru @sgsunder
Would this be mergeable if the comments get addressed? I may look into it if that's the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-revision This PR needs edits
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants