search-simpler-query-fix
All checks were successful
Deploy to core / deploy (push) Successful in 1m45s
All checks were successful
Deploy to core / deploy (push) Successful in 1m45s
This commit is contained in:
parent
00a672f96e
commit
5e4ef40b21
|
@ -1,3 +1,5 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
from sqlalchemy import bindparam, distinct, or_
|
from sqlalchemy import bindparam, distinct, or_
|
||||||
from sqlalchemy.orm import aliased, joinedload, selectinload
|
from sqlalchemy.orm import aliased, joinedload, selectinload
|
||||||
from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select
|
from sqlalchemy.sql.expression import and_, asc, case, desc, func, nulls_last, select
|
||||||
|
@ -16,6 +18,10 @@ from services.search import SearchService
|
||||||
from services.viewed import ViewedStorage
|
from services.viewed import ViewedStorage
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('[resolvers.reader] ')
|
||||||
|
logger.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
|
||||||
def apply_filters(q, filters, author_id=None):
|
def apply_filters(q, filters, author_id=None):
|
||||||
if filters.get('reacted') and author_id:
|
if filters.get('reacted') and author_id:
|
||||||
q.join(Reaction, Reaction.created_by == author_id)
|
q.join(Reaction, Reaction.created_by == author_id)
|
||||||
|
@ -328,27 +334,20 @@ async def load_shouts_search(_, _info, text, limit=50, offset=0):
|
||||||
if text and len(text) > 2:
|
if text and len(text) > 2:
|
||||||
results = await SearchService.search(text, limit, offset)
|
results = await SearchService.search(text, limit, offset)
|
||||||
results_dict = {r['slug']: r for r in results}
|
results_dict = {r['slug']: r for r in results}
|
||||||
found_keys = results_dict.keys()
|
found_keys = list(results_dict.keys())
|
||||||
|
|
||||||
q = (
|
q = select(Shout).where(
|
||||||
select(Shout)
|
|
||||||
.options(
|
|
||||||
joinedload(Shout.authors),
|
|
||||||
joinedload(Shout.topics),
|
|
||||||
)
|
|
||||||
.where(
|
|
||||||
and_(
|
and_(
|
||||||
Shout.deleted_at.is_(None),
|
Shout.deleted_at.is_(None),
|
||||||
Shout.slug.in_(found_keys),
|
Shout.slug.in_(found_keys),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
shouts_data = []
|
shouts_data = []
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
results = list(session.execute(q).unique())
|
results = list(session.execute(q).unique())
|
||||||
# print(results)
|
# print(results)
|
||||||
print(f'[resolvers.reader] searched, preparing {len(results)} results')
|
logger.debug(f'search found {len(results)} results')
|
||||||
for x in results:
|
for x in results:
|
||||||
shout = x[0]
|
shout = x[0]
|
||||||
shout_data = shout.dict()
|
shout_data = shout.dict()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user