schema-fix

This commit is contained in:
Untone 2023-11-23 23:30:00 +03:00
parent 7d5dc8b8cd
commit c150d28447
3 changed files with 18 additions and 37 deletions

View File

@ -1,5 +1,7 @@
[0.2.14]
- schema: some fixes from migrator
- schema: .days -> .time_ago
- schema: excludeLayout + layout in filters -> layouts
- services: db access simpler, no contextmanager
- services: removed Base.create() method
- services: rediscache updated

View File

@ -15,9 +15,7 @@ def add_stat_columns(q):
aliased_reaction = aliased(Reaction)
q = q.outerjoin(aliased_reaction).add_columns(
func.sum(aliased_reaction.id).label("reacted_stat"),
func.sum(
case((aliased_reaction.kind == ReactionKind.COMMENT, 1), else_=0)
).label("commented_stat"),
func.sum(case((aliased_reaction.kind == ReactionKind.COMMENT, 1), else_=0)).label("commented_stat"),
func.sum(
case(
# do not count comments' reactions
@ -54,8 +52,8 @@ def apply_filters(q, filters, author_id=None):
if v == "community":
q = q.filter(Shout.visibility.in_(["public", "community"]))
if filters.get("layout"):
q = q.filter(Shout.layout == filters.get("layout"))
if filters.get("layouts"):
q = q.filter(Shout.layout.in_(filters.get("layouts")))
if filters.get("author"):
q = q.filter(Shout.authors.any(slug=filters.get("author")))
if filters.get("topic"):
@ -104,9 +102,7 @@ async def load_shout(_, _info, slug=None, shout_id=None):
"rating": rating_stat,
}
for author_caption in (
session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug)
):
for author_caption in session.query(ShoutAuthor).join(Shout).where(Shout.slug == slug):
for author in shout.authors:
if author.id == author_caption.author:
author.caption = author_caption.caption
@ -154,18 +150,11 @@ async def load_shouts_by(_, info, options):
order_by = options.get("order_by", Shout.published_at)
query_order_by = (
desc(order_by) if options.get("order_by_desc", True) else asc(order_by)
)
query_order_by = desc(order_by) if options.get("order_by_desc", True) else asc(order_by)
offset = options.get("offset", 0)
limit = options.get("limit", 10)
q = (
q.group_by(Shout.id)
.order_by(nulls_last(query_order_by))
.limit(limit)
.offset(offset)
)
q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset)
shouts = []
shouts_map = {}
@ -201,10 +190,7 @@ async def get_my_feed(_, info, options):
select(Shout.id)
.where(Shout.id == ShoutAuthor.shout)
.where(Shout.id == ShoutTopic.shout)
.where(
(ShoutAuthor.author.in_(author_followed_authors))
| (ShoutTopic.topic.in_(author_followed_topics))
)
.where((ShoutAuthor.author.in_(author_followed_authors)) | (ShoutTopic.topic.in_(author_followed_topics)))
)
q = (
@ -227,18 +213,11 @@ async def get_my_feed(_, info, options):
order_by = options.get("order_by", Shout.published_at)
query_order_by = (
desc(order_by) if options.get("order_by_desc", True) else asc(order_by)
)
query_order_by = desc(order_by) if options.get("order_by_desc", True) else asc(order_by)
offset = options.get("offset", 0)
limit = options.get("limit", 10)
q = (
q.group_by(Shout.id)
.order_by(nulls_last(query_order_by))
.limit(limit)
.offset(offset)
)
q = q.group_by(Shout.id).order_by(nulls_last(query_order_by)).limit(limit).offset(offset)
shouts = []
for [

View File

@ -212,7 +212,7 @@ input ReactionInput {
shout: Int!
range: String
body: String
replyTo: Int
reply_to: Int
}
input AuthorsBy {
@ -222,7 +222,7 @@ input AuthorsBy {
name: String
topic: String
order: String
days: Int
time_ago: Int
stat: String
}
@ -234,9 +234,9 @@ input ShoutsFilterBy {
topics: [String]
author: String
authors: [String]
layout: String
layouts: [String]
visibility: String
days: Int
time_ago: Int
stat: String
}
@ -245,9 +245,9 @@ input LoadShoutsFilters {
body: String
topic: String
author: String
layout: String
layouts: [String]
visibility: String
days: Int
time_ago: Int
reacted: Boolean
}
@ -267,7 +267,7 @@ input ReactionBy {
comment: Boolean
topic: String
created_by: Int
days: Int
time_ago: Int
sort: String
}