diff options
| author | Ruin0x11 | 2020-05-04 02:20:23 -0700 |
|---|---|---|
| committer | Ruin0x11 | 2020-05-04 02:20:23 -0700 |
| commit | 8795279a73e976a3aadbb4b9067209a46f138733 (patch) | |
| tree | 8d0742d03bd5c2847c5fd813fb3105be961c3b88 /server | |
| parent | e6bf102bc03504d9abc584f15da70a5fed7fa950 (diff) | |
Add pool input box in post details
Diffstat (limited to 'server')
| -rw-r--r-- | server/szurubooru/db.py | 19 | ||||
| -rw-r--r-- | server/szurubooru/func/posts.py | 11 | ||||
| -rw-r--r-- | server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py | 2 | ||||
| -rw-r--r-- | server/szurubooru/model/pool.py | 5 | ||||
| -rw-r--r-- | server/szurubooru/model/post.py | 9 |
5 files changed, 41 insertions, 5 deletions
diff --git a/server/szurubooru/db.py b/server/szurubooru/db.py index 561b748..bd30042 100644 --- a/server/szurubooru/db.py +++ b/server/szurubooru/db.py @@ -34,3 +34,22 @@ def _bump_query_count() -> None: sa.event.listen(_engine, 'after_execute', lambda *args: _bump_query_count()) + +import time +import logging + +logger = logging.getLogger("myapp.sqltime") +logger.setLevel(logging.INFO) + +def before_cursor_execute(conn, cursor, statement, + parameters, context, executemany): + conn.info.setdefault('query_start_time', []).append(time.time()) + logger.info("Start Query: %s" % statement) + +def after_cursor_execute(conn, cursor, statement, + parameters, context, executemany): + total = time.time() - conn.info['query_start_time'].pop(-1) + logger.info("Total Time: %f" % total) + +sa.event.listen(_engine, "before_cursor_execute", before_cursor_execute) +sa.event.listen(_engine, "after_cursor_execute", after_cursor_execute) diff --git a/server/szurubooru/func/posts.py b/server/szurubooru/func/posts.py index 64b00c9..723a466 100644 --- a/server/szurubooru/func/posts.py +++ b/server/szurubooru/func/posts.py @@ -5,7 +5,7 @@ from datetime import datetime import sqlalchemy as sa from szurubooru import config, db, model, errors, rest from szurubooru.func import ( - users, scores, comments, tags, util, + users, scores, comments, tags, pools, util, mime, images, files, image_hash, serialization, snapshots) @@ -176,6 +176,7 @@ class PostSerializer(serialization.BaseSerializer): 'hasCustomThumbnail': self.serialize_has_custom_thumbnail, 'notes': self.serialize_notes, 'comments': self.serialize_comments, + 'pools': self.serialize_pools, } def serialize_id(self) -> Any: @@ -299,6 +300,14 @@ class PostSerializer(serialization.BaseSerializer): self.post.comments, key=lambda comment: comment.creation_time)] + def serialize_pools(self) -> Any: + return [ + pools.serialize_pool(pool) + for pool in sorted( + self.post.pools, + key=lambda pool: pool.creation_time)] + + def serialize_post( post: Optional[model.Post], diff --git a/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py b/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py index be87340..88472e3 100644 --- a/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py +++ b/server/szurubooru/migrations/versions/6a2f424ec9d2_create_pool_tables.py @@ -48,7 +48,7 @@ def upgrade(): op.create_table( 'pool_post', sa.Column('pool_id', sa.Integer(), nullable=False), - sa.Column('post_id', sa.Integer(), nullable=False), + sa.Column('post_id', sa.Integer(), nullable=False, index=True), sa.Column('ord', sa.Integer(), nullable=False, index=True), sa.ForeignKeyConstraint(['pool_id'], ['pool.id'], ondelete='CASCADE'), sa.ForeignKeyConstraint(['post_id'], ['post.id'], ondelete='CASCADE'), diff --git a/server/szurubooru/model/pool.py b/server/szurubooru/model/pool.py index ecd6522..8f7c605 100644 --- a/server/szurubooru/model/pool.py +++ b/server/szurubooru/model/pool.py @@ -2,7 +2,6 @@ import sqlalchemy as sa from sqlalchemy.ext.orderinglist import ordering_list from sqlalchemy.ext.associationproxy import association_proxy from szurubooru.model.base import Base -import szurubooru.model as model class PoolName(Base): @@ -43,9 +42,9 @@ class PoolPost(Base): order = sa.Column('ord', sa.Integer, nullable=False, index=True) pool = sa.orm.relationship('Pool', back_populates='_posts') - post = sa.orm.relationship('Post') + post = sa.orm.relationship('Post', back_populates='_pools') - def __init__(self, post: model.Post) -> None: + def __init__(self, post) -> None: self.post_id = post.post_id class Pool(Base): diff --git a/server/szurubooru/model/post.py b/server/szurubooru/model/post.py index f8f5c34..56eaefa 100644 --- a/server/szurubooru/model/post.py +++ b/server/szurubooru/model/post.py @@ -2,7 +2,10 @@ from typing import List import sqlalchemy as sa from szurubooru.model.base import Base from szurubooru.model.comment import Comment +from szurubooru.model.pool import PoolPost +from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.hybrid import hybrid_property +from sqlalchemy.ext.orderinglist import ordering_list class PostFeature(Base): @@ -224,6 +227,12 @@ class Post(Base): notes = sa.orm.relationship( 'PostNote', cascade='all, delete-orphan', lazy='joined') comments = sa.orm.relationship('Comment', cascade='all, delete-orphan') + _pools = sa.orm.relationship( + 'PoolPost', + lazy='select', + order_by='PoolPost.order', + back_populates='post') + pools = association_proxy('_pools', 'pool') # dynamic columns tag_count = sa.orm.column_property( |