server/image_search: add migrations for elasticsearch removal
This commit is contained in:
parent
bd9284b7f8
commit
6cc2a91632
3 changed files with 46 additions and 6 deletions
|
@ -8,7 +8,8 @@ import coloredlogs
|
|||
import sqlalchemy as sa
|
||||
import sqlalchemy.orm.exc
|
||||
from szurubooru import config, db, errors, rest
|
||||
from szurubooru.func import file_uploads
|
||||
from szurubooru.func.posts import update_all_post_signatures
|
||||
from szurubooru.func.file_uploads import purge_old_uploads
|
||||
# pylint: disable=unused-import
|
||||
from szurubooru import api, middleware
|
||||
|
||||
|
@ -106,10 +107,10 @@ def validate_config() -> None:
|
|||
'From address must be set to use mail-based password reset')
|
||||
|
||||
|
||||
def purge_old_uploads() -> None:
|
||||
def purge_old_uploads_daemon() -> None:
|
||||
while True:
|
||||
try:
|
||||
file_uploads.purge_old_uploads()
|
||||
purge_old_uploads()
|
||||
except Exception as ex:
|
||||
logging.exception(ex)
|
||||
time.sleep(60 * 5)
|
||||
|
@ -125,10 +126,14 @@ def create_app() -> Callable[[Any, Any], Any]:
|
|||
if config.config['show_sql']:
|
||||
logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
|
||||
|
||||
purge_thread = threading.Thread(target=purge_old_uploads)
|
||||
purge_thread = threading.Thread(target=purge_old_uploads_daemon)
|
||||
purge_thread.daemon = True
|
||||
purge_thread.start()
|
||||
|
||||
hashing_thread = threading.Thread(target=update_all_post_signatures)
|
||||
hashing_thread.daemon = False
|
||||
hashing_thread.start()
|
||||
|
||||
db.session.commit()
|
||||
|
||||
rest.errors.handle(errors.AuthError, _on_auth_error)
|
||||
|
|
|
@ -513,8 +513,13 @@ def update_all_post_signatures() -> None:
|
|||
.order_by(model.Post.post_id.asc())
|
||||
.all())
|
||||
for post in posts_to_hash:
|
||||
logger.info('Generating hash info for %d', post.post_id)
|
||||
generate_post_signature(post, files.get(get_post_content_path(post)))
|
||||
try:
|
||||
generate_post_signature(
|
||||
post, files.get(get_post_content_path(post)))
|
||||
db.session.commit()
|
||||
logger.info('Hashed Post %d', post.post_id)
|
||||
except Exception as ex:
|
||||
logger.exception(ex)
|
||||
|
||||
|
||||
def update_post_content(post: model.Post, content: Optional[bytes]) -> None:
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
'''
|
||||
Generate post signature table
|
||||
|
||||
Revision ID: 52d6ea6584b8
|
||||
Created at: 2020-03-07 17:03:40.193512
|
||||
'''
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
|
||||
|
||||
revision = '52d6ea6584b8'
|
||||
down_revision = '3c1f0316fa7f'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
|
||||
def upgrade():
|
||||
ArrayType = sa.dialects.postgresql.ARRAY(sa.Integer, dimensions=1)
|
||||
op.create_table(
|
||||
'post_signature',
|
||||
sa.Column('post_id', sa.Integer(), nullable=False),
|
||||
sa.Column('signature', sa.LargeBinary(), nullable=False),
|
||||
sa.Column('words', ArrayType, nullable=False),
|
||||
sa.ForeignKeyConstraint(['post_id'], ['post.id']),
|
||||
sa.PrimaryKeyConstraint('post_id'))
|
||||
|
||||
|
||||
def downgrade():
|
||||
op.drop_table('post_signature')
|
Loading…
Reference in a new issue