This commit is contained in:
parent
0533863230
commit
ea99219283
|
@ -24,6 +24,7 @@ from services.schema import query
|
||||||
from services.search import search_text
|
from services.search import search_text
|
||||||
from services.viewed import ViewedStorage
|
from services.viewed import ViewedStorage
|
||||||
|
|
||||||
|
|
||||||
def query_shouts():
|
def query_shouts():
|
||||||
"""
|
"""
|
||||||
Базовый запрос для получения публикаций с подзапросами статистики, авторов и тем,
|
Базовый запрос для получения публикаций с подзапросами статистики, авторов и тем,
|
||||||
|
@ -105,6 +106,7 @@ def query_shouts():
|
||||||
|
|
||||||
return q, aliased_reaction
|
return q, aliased_reaction
|
||||||
|
|
||||||
|
|
||||||
def parse_aggregated_string(aggregated_str):
|
def parse_aggregated_string(aggregated_str):
|
||||||
"""
|
"""
|
||||||
Преобразует строку, полученную из string_agg, обратно в список словарей.
|
Преобразует строку, полученную из string_agg, обратно в список словарей.
|
||||||
|
@ -119,7 +121,7 @@ def parse_aggregated_string(aggregated_str):
|
||||||
for item_str in aggregated_str.split(", "):
|
for item_str in aggregated_str.split(", "):
|
||||||
item_data = {}
|
item_data = {}
|
||||||
for field in item_str.split(";"):
|
for field in item_str.split(";"):
|
||||||
if ':' in field:
|
if ":" in field:
|
||||||
key, value = field.split(":", 1)
|
key, value = field.split(":", 1)
|
||||||
item_data[key] = value
|
item_data[key] = value
|
||||||
else:
|
else:
|
||||||
|
@ -130,6 +132,7 @@ def parse_aggregated_string(aggregated_str):
|
||||||
|
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
def get_shouts_with_stats(q, limit, offset=0, author_id=None):
|
def get_shouts_with_stats(q, limit, offset=0, author_id=None):
|
||||||
"""
|
"""
|
||||||
Получение публикаций со статистикой, и подзапросами авторов и тем.
|
Получение публикаций со статистикой, и подзапросами авторов и тем.
|
||||||
|
@ -177,6 +180,7 @@ def get_shouts_with_stats(q, limit, offset=0, author_id=None):
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
|
|
||||||
def filter_my(info, session, q):
|
def filter_my(info, session, q):
|
||||||
"""
|
"""
|
||||||
Фильтрация публикаций, основанная на подписках пользователя.
|
Фильтрация публикаций, основанная на подписках пользователя.
|
||||||
|
@ -208,6 +212,7 @@ def filter_my(info, session, q):
|
||||||
q = q.filter(Shout.id.in_(subquery))
|
q = q.filter(Shout.id.in_(subquery))
|
||||||
return q, reader_id
|
return q, reader_id
|
||||||
|
|
||||||
|
|
||||||
def apply_filters(q, filters, author_id=None):
|
def apply_filters(q, filters, author_id=None):
|
||||||
"""
|
"""
|
||||||
Применение фильтров к запросу.
|
Применение фильтров к запросу.
|
||||||
|
@ -250,6 +255,7 @@ def apply_filters(q, filters, author_id=None):
|
||||||
|
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
|
||||||
@query.field("get_shout")
|
@query.field("get_shout")
|
||||||
async def get_shout(_, info, slug: str):
|
async def get_shout(_, info, slug: str):
|
||||||
"""
|
"""
|
||||||
|
@ -318,9 +324,11 @@ async def get_shout(_, info, slug: str):
|
||||||
return shout
|
return shout
|
||||||
except Exception as _exc:
|
except Exception as _exc:
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shouts_by")
|
@query.field("load_shouts_by")
|
||||||
async def load_shouts_by(_, _info, options):
|
async def load_shouts_by(_, _info, options):
|
||||||
"""
|
"""
|
||||||
|
@ -557,6 +565,7 @@ async def load_shouts_discussed(_, info, limit=50, offset=0):
|
||||||
q = q.filter(Shout.id.in_(reaction_subquery))
|
q = q.filter(Shout.id.in_(reaction_subquery))
|
||||||
return get_shouts_with_stats(q, limit, offset=offset)
|
return get_shouts_with_stats(q, limit, offset=offset)
|
||||||
|
|
||||||
|
|
||||||
async def reacted_shouts_updates(follower_id: int, limit=50, offset=0) -> List[Shout]:
|
async def reacted_shouts_updates(follower_id: int, limit=50, offset=0) -> List[Shout]:
|
||||||
"""
|
"""
|
||||||
Обновляет публикации, на которые подписан автор, с учетом реакций.
|
Обновляет публикации, на которые подписан автор, с учетом реакций.
|
||||||
|
@ -587,6 +596,7 @@ async def reacted_shouts_updates(follower_id: int, limit=50, offset=0) -> List[S
|
||||||
|
|
||||||
return shouts
|
return shouts
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shouts_followed")
|
@query.field("load_shouts_followed")
|
||||||
@login_required
|
@login_required
|
||||||
async def load_shouts_followed(_, info, limit=50, offset=0) -> List[Shout]:
|
async def load_shouts_followed(_, info, limit=50, offset=0) -> List[Shout]:
|
||||||
|
@ -610,6 +620,7 @@ async def load_shouts_followed(_, info, limit=50, offset=0) -> List[Shout]:
|
||||||
logger.debug(error)
|
logger.debug(error)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
@query.field("load_shouts_followed_by")
|
@query.field("load_shouts_followed_by")
|
||||||
async def load_shouts_followed_by(_, info, slug: str, limit=50, offset=0) -> List[Shout]:
|
async def load_shouts_followed_by(_, info, slug: str, limit=50, offset=0) -> List[Shout]:
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user