Add docker image building

This commit is contained in:
2022-01-29 18:52:28 +03:00
parent 87108fb1bd
commit bbb5a4748c
9 changed files with 453 additions and 17 deletions

View File

@@ -34,12 +34,18 @@ async def update_books(ctx) -> bool:
count = await postgres_pool.fetchval("SELECT count(*) FROM books;")
for offset in range(0, count, 4096):
rows = await postgres_pool.fetch(f"SELECT id, title, is_deleted FROM books ORDER BY id LIMIT 4096 OFFSET {offset}")
rows = await postgres_pool.fetch(
"SELECT id, title, is_deleted FROM books"
f" ORDER BY id LIMIT 4096 OFFSET {offset}"
)
documents = [dict(row) for row in rows]
await loop.run_in_executor(pool, index.add_documents, documents)
index.update_searchable_attributes(["title"])
index.update_filterable_attributes(["is_deleted"])
return True
@@ -55,12 +61,17 @@ async def update_authors(ctx) -> bool:
count = await postgres_pool.fetchval("SELECT count(*) FROM authors;")
for offset in range(0, count, 4096):
rows = await postgres_pool.fetch(f"SELECT id, first_name, last_name, middle_name FROM authors ORDER BY id LIMIT 4096 OFFSET {offset}")
rows = await postgres_pool.fetch(
"SELECT id, first_name, last_name, middle_name FROM authors"
f" ORDER BY id LIMIT 4096 OFFSET {offset}"
)
documents = [dict(row) for row in rows]
await loop.run_in_executor(pool, index.add_documents, documents)
index.update_searchable_attributes(["first_name", "last_name", "middle_name"])
return True
@@ -76,12 +87,16 @@ async def update_sequences(ctx) -> bool:
count = await postgres_pool.fetchval("SELECT count(*) FROM sequences;")
for offset in range(0, count, 4096):
rows = await postgres_pool.fetch(f"SELECT id, name FROM sequences ORDER BY id LIMIT 4096 OFFSET {offset}")
rows = await postgres_pool.fetch(
f"SELECT id, name FROM sequences ORDER BY id LIMIT 4096 OFFSET {offset}"
)
documents = [dict(row) for row in rows]
await loop.run_in_executor(pool, index.add_documents, documents)
index.update_searchable_attributes(["name"])
return True

View File

@@ -5,10 +5,7 @@ from arq.connections import ArqRedis
from app.depends import check_token
router = APIRouter(
prefix="/api/v1",
dependencies=[Depends(check_token)]
)
router = APIRouter(prefix="/api/v1", dependencies=[Depends(check_token)])
@router.post("/update")

View File

@@ -1,9 +1,4 @@
from app.services import (
update,
update_books,
update_authors,
update_sequences,
)
from app.services import update, update_books, update_authors, update_sequences
from core.arq_pool import get_redis_settings, get_arq_pool