new-version-0-2-13
Some checks failed
deploy / deploy (push) Failing after 1m54s

This commit is contained in:
2023-11-03 13:10:22 +03:00
parent 1f5e5472c9
commit 435d1e4505
21 changed files with 392 additions and 436 deletions

View File

@@ -1,10 +1,11 @@
import time
from typing import List
from datetime import datetime, timedelta, timezone
from sqlalchemy import and_, func, distinct, select, literal
from sqlalchemy.orm import aliased
from services.auth import login_required
from services.db import local_session
from services.unread import get_total_unread_counter
from services.schema import mutation, query
from orm.shout import ShoutAuthor, ShoutTopic
from orm.topic import Topic
@@ -41,7 +42,7 @@ def add_author_stat_columns(q):
# )
q = q.add_columns(literal(0).label("commented_stat"))
# q = q.outerjoin(Reaction, and_(Reaction.createdBy == Author.id, Reaction.body.is_not(None))).add_columns(
# q = q.outerjoin(Reaction, and_(Reaction.created_by == Author.id, Reaction.body.is_not(None))).add_columns(
# func.count(distinct(Reaction.id)).label('commented_stat')
# )
@@ -81,7 +82,7 @@ def get_authors_from_query(q):
async def author_followings(author_id: int):
return {
# "unread": await get_total_unread_counter(author_id), # unread inbox messages counter
"unread": await get_total_unread_counter(author_id), # unread inbox messages counter
"topics": [
t.slug for t in await followed_topics(author_id)
], # followed topics slugs
@@ -168,14 +169,15 @@ async def load_authors_by(_, _info, by, limit, offset):
.join(Topic)
.where(Topic.slug == by["topic"])
)
if by.get("lastSeen"): # in days
days_before = datetime.now(tz=timezone.utc) - timedelta(days=by["lastSeen"])
q = q.filter(Author.lastSeen > days_before)
elif by.get("createdAt"): # in days
days_before = datetime.now(tz=timezone.utc) - timedelta(days=by["createdAt"])
q = q.filter(Author.createdAt > days_before)
if by.get("last_seen"): # in unixtime
before = int(time.time()) - by["last_seen"]
q = q.filter(Author.last_seen > before)
elif by.get("created_at"): # in unixtime
before = int(time.time()) - by["created_at"]
q = q.filter(Author.created_at > before)
q = q.order_by(by.get("order", Author.createdAt)).limit(limit).offset(offset)
q = q.order_by(by.get("order", Author.created_at)).limit(limit).offset(offset)
return get_authors_from_query(q)
@@ -226,7 +228,8 @@ async def rate_author(_, info, rated_user_id, value):
session.query(AuthorRating)
.filter(
and_(
AuthorRating.rater == author_id, AuthorRating.user == rated_user_id
AuthorRating.rater == author_id,
AuthorRating.user == rated_user_id
)
)
.first()

View File

@@ -28,7 +28,7 @@ def add_community_stat_columns(q):
# )
q = q.add_columns(literal(0).label("commented_stat"))
# q = q.outerjoin(Reaction, and_(Reaction.createdBy == Author.id, Reaction.body.is_not(None))).add_columns(
# q = q.outerjoin(Reaction, and_(Reaction.created_by == Author.id, Reaction.body.is_not(None))).add_columns(
# func.count(distinct(Reaction.id)).label('commented_stat')
# )

View File

@@ -1,40 +1,32 @@
from datetime import datetime, timezone
import time # For Unix timestamps
from sqlalchemy import and_, select
from sqlalchemy.orm import joinedload
from services.auth import login_required
from services.db import local_session
from services.schema import mutation, query
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.shout import Shout, ShoutAuthor, ShoutTopic, ShoutVisibility
from orm.topic import Topic
from reaction import reactions_follow, reactions_unfollow
from services.notify import notify_shout
@query.field("loadDrafts")
async def get_drafts(_, info):
author = info.context["request"].author
q = (
select(Shout)
.options(
joinedload(Shout.authors),
joinedload(Shout.topics),
)
.where(and_(Shout.deletedAt.is_(None), Shout.createdBy == author.id))
.where(and_(Shout.deleted_at.is_(None), Shout.created_by == author.id))
)
q = q.group_by(Shout.id)
shouts = []
with local_session() as session:
for [shout] in session.execute(q).unique():
shouts.append(shout)
return shouts
@mutation.field("createShout")
@login_required
async def create_shout(_, info, inp):
@@ -43,7 +35,8 @@ async def create_shout(_, info, inp):
topics = (
session.query(Topic).filter(Topic.slug.in_(inp.get("topics", []))).all()
)
# Replace datetime with Unix timestamp
current_time = int(time.time())
new_shout = Shout.create(
**{
"title": inp.get("title"),
@@ -54,43 +47,33 @@ async def create_shout(_, info, inp):
"layout": inp.get("layout"),
"authors": inp.get("authors", []),
"slug": inp.get("slug"),
"mainTopic": inp.get("mainTopic"),
"visibility": "authors",
"createdBy": author_id,
"topics": inp.get("topics"),
"visibility": ShoutVisibility.AUTHORS,
"created_id": author_id,
"created_at": current_time, # Set created_at as Unix timestamp
}
)
for topic in topics:
t = ShoutTopic.create(topic=topic.id, shout=new_shout.id)
session.add(t)
# NOTE: shout made by one first author
sa = ShoutAuthor.create(shout=new_shout.id, author=author_id)
session.add(sa)
session.add(new_shout)
reactions_follow(author_id, new_shout.id, True)
session.commit()
# TODO
# GitTask(inp, user.username, user.email, "new shout %s" % new_shout.slug)
# TODO: GitTask(inp, user.username, user.email, "new shout %s" % new_shout.slug)
if new_shout.slug is None:
new_shout.slug = f"draft-{new_shout.id}"
session.commit()
else:
notify_shout(new_shout.dict(), "create")
return {"shout": new_shout}
@mutation.field("updateShout")
@login_required
async def update_shout(_, info, shout_id, shout_input=None, publish=False):
author_id = info.context["author_id"]
with local_session() as session:
shout = (
session.query(Shout)
@@ -101,39 +84,30 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
.filter(Shout.id == shout_id)
.first()
)
if not shout:
return {"error": "shout not found"}
if shout.createdBy != author_id:
if shout.created_by != author_id:
return {"error": "access denied"}
updated = False
if shout_input is not None:
topics_input = shout_input["topics"]
del shout_input["topics"]
new_topics_to_link = []
new_topics = [
topic_input for topic_input in topics_input if topic_input["id"] < 0
]
for new_topic in new_topics:
del new_topic["id"]
created_new_topic = Topic.create(**new_topic)
session.add(created_new_topic)
new_topics_to_link.append(created_new_topic)
if len(new_topics) > 0:
session.commit()
for new_topic_to_link in new_topics_to_link:
created_unlinked_topic = ShoutTopic.create(
shout=shout.id, topic=new_topic_to_link.id
)
session.add(created_unlinked_topic)
existing_topics_input = [
topic_input
for topic_input in topics_input
@@ -145,80 +119,61 @@ async def update_shout(_, info, shout_id, shout_input=None, publish=False):
if existing_topic_input["id"]
not in [topic.id for topic in shout.topics]
]
for existing_topic_to_link_id in existing_topic_to_link_ids:
created_unlinked_topic = ShoutTopic.create(
shout=shout.id, topic=existing_topic_to_link_id
)
session.add(created_unlinked_topic)
topic_to_unlink_ids = [
topic.id
for topic in shout.topics
if topic.id
not in [topic_input["id"] for topic_input in existing_topics_input]
]
shout_topics_to_remove = session.query(ShoutTopic).filter(
and_(
ShoutTopic.shout == shout.id,
ShoutTopic.topic.in_(topic_to_unlink_ids),
)
)
for shout_topic_to_remove in shout_topics_to_remove:
session.delete(shout_topic_to_remove)
shout_input["mainTopic"] = shout_input["mainTopic"]["slug"]
if shout_input["mainTopic"] == "":
del shout_input["mainTopic"]
# Replace datetime with Unix timestamp
current_time = int(time.time())
shout_input["updated_at"] = current_time # Set updated_at as Unix timestamp
shout.update(shout_input)
updated = True
# TODO: use visibility setting
if publish and shout.visibility == "authors":
shout.visibility = "community"
shout.publishedAt = datetime.now(tz=timezone.utc)
shout.published_at = current_time # Set published_at as Unix timestamp
updated = True
# notify on publish
notify_shout(shout.dict())
if updated:
shout.updatedAt = datetime.now(tz=timezone.utc)
session.commit()
session.commit()
# GitTask(inp, user.username, user.email, "update shout %s" % slug)
notify_shout(shout.dict(), "update")
return {"shout": shout}
@mutation.field("deleteShout")
@login_required
async def delete_shout(_, info, shout_id):
author_id = info.context["author_id"]
with local_session() as session:
shout = session.query(Shout).filter(Shout.id == shout_id).first()
if not shout:
return {"error": "invalid shout id"}
if author_id != shout.createdBy:
if author_id != shout.created_by:
return {"error": "access denied"}
for author_id in shout.authors:
reactions_unfollow(author_id, shout_id)
shout.deletedAt = datetime.now(tz=timezone.utc)
# Replace datetime with Unix timestamp
current_time = int(time.time())
shout.deleted_at = current_time # Set deleted_at as Unix timestamp
session.commit()
notify_shout(shout.dict(), "delete")
return {}

View File

@@ -1,4 +1,4 @@
from datetime import datetime, timedelta, timezone
import time
from sqlalchemy import and_, asc, desc, select, text, func, case
from sqlalchemy.orm import aliased
from services.notify import notify_reaction
@@ -15,7 +15,7 @@ def add_reaction_stat_columns(q):
aliased_reaction = aliased(Reaction)
q = q.outerjoin(
aliased_reaction, Reaction.id == aliased_reaction.replyTo
aliased_reaction, Reaction.id == aliased_reaction.reply_to
).add_columns(
func.sum(aliased_reaction.id).label("reacted_stat"),
func.sum(case((aliased_reaction.body.is_not(None), 1), else_=0)).label(
@@ -96,7 +96,7 @@ def is_published_author(session, author_id):
return (
session.query(Shout)
.where(Shout.authors.contains(author_id))
.filter(and_(Shout.publishedAt.is_not(None), Shout.deletedAt.is_(None)))
.filter(and_(Shout.published_at.is_not(None), Shout.deleted_at.is_(None)))
.count()
> 0
)
@@ -104,7 +104,7 @@ def is_published_author(session, author_id):
def check_to_publish(session, author_id, reaction):
"""set shout to public if publicated approvers amount > 4"""
if not reaction.replyTo and reaction.kind in [
if not reaction.reply_to and reaction.kind in [
ReactionKind.ACCEPT,
ReactionKind.LIKE,
ReactionKind.PROOF,
@@ -118,7 +118,7 @@ def check_to_publish(session, author_id, reaction):
author_id,
]
for ar in approvers_reactions:
a = ar.createdBy
a = ar.created_by
if is_published_author(session, a):
approvers.append(a)
if len(approvers) > 4:
@@ -128,7 +128,7 @@ def check_to_publish(session, author_id, reaction):
def check_to_hide(session, reaction):
"""hides any shout if 20% of reactions are negative"""
if not reaction.replyTo and reaction.kind in [
if not reaction.reply_to and reaction.kind in [
ReactionKind.REJECT,
ReactionKind.DISLIKE,
ReactionKind.DISPROOF,
@@ -152,7 +152,7 @@ def check_to_hide(session, reaction):
def set_published(session, shout_id):
s = session.query(Shout).where(Shout.id == shout_id).first()
s.publishedAt = datetime.now(tz=timezone.utc)
s.published_at = int(time.time())
s.visibility = text("public")
session.add(s)
session.commit()
@@ -170,7 +170,7 @@ def set_hidden(session, shout_id):
async def create_reaction(_, info, reaction):
author_id = info.context["author_id"]
with local_session() as session:
reaction["createdBy"] = author_id
reaction["created_by"] = author_id
shout = session.query(Shout).where(Shout.id == reaction["shout"]).one()
if reaction["kind"] in [ReactionKind.DISLIKE.name, ReactionKind.LIKE.name]:
@@ -179,9 +179,9 @@ async def create_reaction(_, info, reaction):
.where(
and_(
Reaction.shout == reaction["shout"],
Reaction.createdBy == author_id,
Reaction.created_by == author_id,
Reaction.kind == reaction["kind"],
Reaction.replyTo == reaction.get("replyTo"),
Reaction.reply_to == reaction.get("reply_to"),
)
)
.first()
@@ -200,9 +200,9 @@ async def create_reaction(_, info, reaction):
.where(
and_(
Reaction.shout == reaction["shout"],
Reaction.createdBy == author_id,
Reaction.created_by == author_id,
Reaction.kind == opposite_reaction_kind,
Reaction.replyTo == reaction.get("replyTo"),
Reaction.reply_to == reaction.get("reply_to"),
)
)
.first()
@@ -215,12 +215,12 @@ async def create_reaction(_, info, reaction):
# Proposal accepting logix
if (
r.replyTo is not None
r.reply_to is not None
and r.kind == ReactionKind.ACCEPT
and author_id in shout.dict()["authors"]
):
replied_reaction = (
session.query(Reaction).where(Reaction.id == r.replyTo).first()
session.query(Reaction).where(Reaction.id == r.reply_to).first()
)
if replied_reaction and replied_reaction.kind == ReactionKind.PROPOSE:
if replied_reaction.range:
@@ -237,7 +237,7 @@ async def create_reaction(_, info, reaction):
rdict = r.dict()
rdict["shout"] = shout.dict()
author = session.query(Author).where(Author.id == author_id).first()
rdict["createdBy"] = author.dict()
rdict["created_by"] = author.dict()
# self-regulation mechanics
@@ -274,11 +274,11 @@ async def update_reaction(_, info, rid, reaction={}):
if not r:
return {"error": "invalid reaction id"}
if r.createdBy != author_id:
if r.created_by != author_id:
return {"error": "access denied"}
r.body = reaction["body"]
r.updatedAt = datetime.now(tz=timezone.utc)
r.updated_at = int(time.time())
if r.kind != reaction["kind"]:
# NOTE: change mind detection can be here
pass
@@ -304,13 +304,13 @@ async def delete_reaction(_, info, rid):
r = session.query(Reaction).filter(Reaction.id == rid).first()
if not r:
return {"error": "invalid reaction id"}
if r.createdBy != author_id:
if r.created_by != author_id:
return {"error": "access denied"}
if r.kind in [ReactionKind.LIKE, ReactionKind.DISLIKE]:
session.delete(r)
else:
r.deletedAt = datetime.now(tz=timezone.utc)
r.deleted_at = int(time.time())
session.commit()
notify_reaction(r.dict(), "delete")
@@ -325,11 +325,11 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
:param by: {
:shout - filter by slug
:shouts - filer by shout slug list
:createdBy - to filter by author
:created_by - to filter by author
:topic - to filter by topic
:search - to search by reactions' body
:comment - true if body.length > 0
:days - a number of days ago
:time_ago - amount of time ago
:sort - a fieldname to sort desc by default
}
:param limit: int amount of shouts
@@ -339,7 +339,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
q = (
select(Reaction, Author, Shout)
.join(Author, Reaction.createdBy == Author.id)
.join(Author, Reaction.created_by == Author.id)
.join(Shout, Reaction.shout == Shout.id)
)
@@ -348,8 +348,8 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
elif by.get("shouts"):
q = q.filter(Shout.slug.in_(by["shouts"]))
if by.get("createdBy"):
q = q.filter(Author.id == by.get("createdBy"))
if by.get("created_by"):
q = q.filter(Author.id == by.get("created_by"))
if by.get("topic"):
# TODO: check
@@ -361,15 +361,15 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
if len(by.get("search", "")) > 2:
q = q.filter(Reaction.body.ilike(f'%{by["body"]}%'))
if by.get("days"):
after = datetime.now(tz=timezone.utc) - timedelta(days=int(by["days"]) or 30)
q = q.filter(Reaction.createdAt > after) # FIXME: use comparing operator?
if by.get("time_ago"):
after = int(time.time()) - int(by.get("time_ago", 0))
q = q.filter(Reaction.created_at > after)
order_way = asc if by.get("sort", "").startswith("-") else desc
order_field = by.get("sort", "").replace("-", "") or Reaction.createdAt
order_field = by.get("sort", "").replace("-", "") or Reaction.created_at
q = q.group_by(Reaction.id, Author.id, Shout.id).order_by(order_way(order_field))
q = add_reaction_stat_columns(q)
q = q.where(Reaction.deletedAt.is_(None))
q = q.where(Reaction.deleted_at.is_(None))
q = q.limit(limit).offset(offset)
reactions = []
session = info.context["session"]
@@ -381,7 +381,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
commented_stat,
rating_stat,
] in session.execute(q):
reaction.createdBy = author
reaction.created_by = author
reaction.shout = shout
reaction.stat = {
"rating": rating_stat,
@@ -393,7 +393,7 @@ async def load_reactions_by(_, info, by, limit=50, offset=0):
# ?
if by.get("stat"):
reactions.sort(lambda r: r.stat.get(by["stat"]) or r.createdAt)
reactions.sort(lambda r: r.stat.get(by["stat"]) or r.created_at)
return reactions
@@ -407,8 +407,8 @@ async def followed_reactions(_, info):
author = session.query(Author).where(Author.id == author_id).first()
reactions = (
session.query(Reaction.shout)
.where(Reaction.createdBy == author.id)
.filter(Reaction.createdAt > author.lastSeen)
.where(Reaction.created_by == author.id)
.filter(Reaction.created_at > author.last_seen)
.all()
)

View File

@@ -1,5 +1,4 @@
from datetime import datetime, timedelta, timezone
import time
from aiohttp.web_exceptions import HTTPException
from sqlalchemy.orm import joinedload, aliased
from sqlalchemy.sql.expression import desc, asc, select, func, case, and_, nulls_last
@@ -10,11 +9,11 @@ from orm.topic import TopicFollower
from orm.reaction import Reaction, ReactionKind
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.author import AuthorFollower
from servies.viewed import ViewedStorage
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(
@@ -23,7 +22,7 @@ def add_stat_columns(q):
func.sum(
case(
# do not count comments' reactions
(aliased_reaction.replyTo.is_not(None), 0),
(aliased_reaction.body.is_not(""), 0),
(aliased_reaction.kind == ReactionKind.AGREE, 1),
(aliased_reaction.kind == ReactionKind.DISAGREE, -1),
(aliased_reaction.kind == ReactionKind.PROOF, 1),
@@ -38,7 +37,7 @@ def add_stat_columns(q):
func.max(
case(
(aliased_reaction.kind != ReactionKind.COMMENT, None),
else_=aliased_reaction.createdAt,
else_=aliased_reaction.created_at,
)
).label("last_comment"),
)
@@ -48,7 +47,7 @@ def add_stat_columns(q):
def apply_filters(q, filters, author_id=None):
if filters.get("reacted") and author_id:
q.join(Reaction, Reaction.createdBy == author_id)
q.join(Reaction, Reaction.created_by == author_id)
v = filters.get("visibility")
if v == "public":
@@ -66,11 +65,9 @@ def apply_filters(q, filters, author_id=None):
q = q.filter(Shout.title.ilike(f'%{filters.get("title")}%'))
if filters.get("body"):
q = q.filter(Shout.body.ilike(f'%{filters.get("body")}%s'))
if filters.get("days"):
before = datetime.now(tz=timezone.utc) - timedelta(
days=int(filters.get("days")) or 30
)
q = q.filter(Shout.createdAt > before)
if filters.get("time_ago"):
before = int(time.time()) - int(filters.get("time_ago"))
q = q.filter(Shout.created_at > before)
return q
@@ -89,11 +86,12 @@ async def load_shout(_, _info, slug=None, shout_id=None):
if shout_id is not None:
q = q.filter(Shout.id == shout_id)
q = q.filter(Shout.deletedAt.is_(None)).group_by(Shout.id)
q = q.filter(Shout.deleted_at.is_(None)).group_by(Shout.id)
try:
[
shout,
viewed_stat,
reacted_stat,
commented_stat,
rating_stat,
@@ -101,7 +99,7 @@ async def load_shout(_, _info, slug=None, shout_id=None):
] = session.execute(q).first()
shout.stat = {
"viewed": shout.views,
"viewed": viewed_stat,
"reacted": reacted_stat,
"commented": commented_stat,
"rating": rating_stat,
@@ -134,7 +132,7 @@ async def load_shouts_by(_, info, options):
}
offset: 0
limit: 50
order_by: 'createdAt' | 'commented' | 'reacted' | 'rating'
order_by: 'created_at' | 'commented' | 'reacted' | 'rating'
order_by_desc: true
}
@@ -147,7 +145,7 @@ async def load_shouts_by(_, info, options):
joinedload(Shout.authors),
joinedload(Shout.topics),
)
.where(Shout.deletedAt.is_(None))
.where(Shout.deleted_at.is_(None))
)
q = add_stat_columns(q)
@@ -155,7 +153,7 @@ async def load_shouts_by(_, info, options):
author_id = info.context["author_id"]
q = apply_filters(q, options.get("filters", {}), author_id)
order_by = options.get("order_by", Shout.publishedAt)
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)
@@ -175,6 +173,7 @@ async def load_shouts_by(_, info, options):
with local_session() as session:
for [
shout,
viewed_stat,
reacted_stat,
commented_stat,
rating_stat,
@@ -182,7 +181,7 @@ async def load_shouts_by(_, info, options):
] in session.execute(q).unique():
shouts.append(shout)
shout.stat = {
"viewed": shout.views,
"viewed": viewed_stat,
"reacted": reacted_stat,
"commented": commented_stat,
"rating": rating_stat,
@@ -196,12 +195,17 @@ async def load_shouts_by(_, info, options):
async def get_my_feed(_, info, options):
author_id = info.context["author_id"]
with local_session() as session:
author_followed_authors = select(AuthorFollower.author).where(AuthorFollower.follower == author_id)
author_followed_topics = select(TopicFollower.topic).where(TopicFollower.follower == author_id)
subquery = (
select(Shout.id)
.join(ShoutAuthor)
.join(AuthorFollower, AuthorFollower.follower._is(author_id))
.join(ShoutTopic)
.join(TopicFollower, TopicFollower.follower._is(author_id))
.where(Shout.id == ShoutAuthor.shout)
.where(Shout.id == ShoutTopic.shout)
.where(
(ShoutAuthor.author.in_(author_followed_authors))
| (ShoutTopic.topic.in_(author_followed_topics))
)
)
q = (
@@ -212,8 +216,8 @@ async def get_my_feed(_, info, options):
)
.where(
and_(
Shout.publishedAt.is_not(None),
Shout.deletedAt.is_(None),
Shout.published_at.is_not(None),
Shout.deleted_at.is_(None),
Shout.id.in_(subquery),
)
)
@@ -222,7 +226,7 @@ async def get_my_feed(_, info, options):
q = add_stat_columns(q)
q = apply_filters(q, options.get("filters", {}), author_id)
order_by = options.get("order_by", Shout.publishedAt)
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)
@@ -238,7 +242,6 @@ async def get_my_feed(_, info, options):
)
shouts = []
shouts_map = {}
for [
shout,
reacted_stat,
@@ -246,13 +249,11 @@ async def get_my_feed(_, info, options):
rating_stat,
_last_comment,
] in session.execute(q).unique():
shouts.append(shout)
shout.stat = {
"viewed": shout.views,
"viewed": ViewedStorage.get_shout(shout.slug),
"reacted": reacted_stat,
"commented": commented_stat,
"rating": rating_stat,
}
shouts_map[shout.id] = shout
# FIXME: shouts_map does not go anywhere?
shouts.append(shout)
return shouts

View File

@@ -136,10 +136,7 @@ def topic_follow(follower_id, slug):
try:
with local_session() as session:
topic = session.query(Topic).where(Topic.slug == slug).one()
following = TopicFollower.create(topic=topic.id, follower=follower_id)
session.add(following)
session.commit()
_following = TopicFollower.create(topic=topic.id, follower=follower_id)
return True
except Exception:
return False