diff --git a/orm/author.py b/orm/author.py index 49bf6d18..84fa3f67 100644 --- a/orm/author.py +++ b/orm/author.py @@ -31,7 +31,7 @@ class Author(Base): user = Column(String, unique=True) # unbounded link with authorizer's User type name = Column(String, nullable=True, comment='Display name') - slug = Column(String, unique=True, comment="Author's slug") + slug = Column(String, unique=True, comment="Author's slug", index=True) bio = Column(String, nullable=True, comment='Bio') # status description about = Column(String, nullable=True, comment='About') # long and formatted pic = Column(String, nullable=True, comment='Picture') diff --git a/orm/collection.py b/orm/collection.py index 87592bc8..c0b8d342 100644 --- a/orm/collection.py +++ b/orm/collection.py @@ -16,7 +16,7 @@ class ShoutCollection(Base): class Collection(Base): __tablename__ = 'collection' - slug = Column(String, unique=True) + slug = Column(String, unique=True, index=True) title = Column(String, nullable=False, comment='Title') body = Column(String, nullable=True, comment='Body') pic = Column(String, nullable=True, comment='Picture') diff --git a/orm/community.py b/orm/community.py index ff156bd9..3c186a0c 100644 --- a/orm/community.py +++ b/orm/community.py @@ -21,7 +21,7 @@ class Community(Base): __tablename__ = 'community' name = Column(String, nullable=False) - slug = Column(String, nullable=False, unique=True) + slug = Column(String, nullable=False, unique=True, index=True) desc = Column(String, nullable=False, default='') pic = Column(String, nullable=False, default='') created_at = Column(Integer, nullable=False, default=lambda: int(time.time())) diff --git a/orm/shout.py b/orm/shout.py index 2757bcb6..e5f53d9f 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -61,7 +61,7 @@ class Shout(Base): deleted_by = Column(ForeignKey('author.id'), nullable=True) body = Column(String, nullable=False, comment='Body') - slug = Column(String, unique=True) + slug = Column(String, unique=True, index=True) cover = Column(String, nullable=True, comment='Cover image url') cover_caption = Column(String, nullable=True, comment='Cover image alt caption') lead = Column(String, nullable=True) diff --git a/orm/topic.py b/orm/topic.py index 928b0129..73e0131b 100644 --- a/orm/topic.py +++ b/orm/topic.py @@ -18,7 +18,7 @@ class TopicFollower(Base): class Topic(Base): __tablename__ = 'topic' - slug = Column(String, unique=True) + slug = Column(String, unique=True, index=True) title = Column(String, nullable=False, comment='Title') body = Column(String, nullable=True, comment='Body') pic = Column(String, nullable=True, comment='Picture') diff --git a/services/db.py b/services/db.py index 4a6f54c6..06a84fc5 100644 --- a/services/db.py +++ b/services/db.py @@ -33,12 +33,12 @@ Base = declarative_base() @event.listens_for(Engine, 'before_cursor_execute') def before_cursor_execute(conn, cursor, statement, parameters, context, executemany): conn.info.setdefault('query_start_time', []).append(time.time()) - logger.debug(f" {statement}") + logger.debug(f"\n{statement}") @event.listens_for(Engine, 'after_cursor_execute') def after_cursor_execute(conn, cursor, statement, parameters, context, executemany): total = time.time() - conn.info['query_start_time'].pop(-1) - logger.debug(f' ... {total*1000} s ') + logger.debug(f' ... {total*1000} s\n') def local_session(src=''): return Session(bind=engine, expire_on_commit=False)