fmt
All checks were successful
Deploy on push / deploy (push) Successful in 24s

This commit is contained in:
Untone 2024-05-07 00:06:31 +03:00
parent e61db5d6e5
commit e0a5c654d8
9 changed files with 33 additions and 40 deletions

View File

@ -1,10 +1,12 @@
import time
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
# from sqlalchemy_utils import TSVectorType
from services.db import Base
# from sqlalchemy_utils import TSVectorType
class AuthorRating(Base):
__tablename__ = "author_rating"

View File

@ -11,12 +11,7 @@ from resolvers.author import ( # search_authors,
)
from resolvers.community import get_communities_all, get_community
from resolvers.editor import create_shout, delete_shout, update_shout
from resolvers.follower import (
follow,
get_shout_followers,
get_topic_followers,
unfollow,
)
from resolvers.follower import follow, get_shout_followers, get_topic_followers, unfollow
from resolvers.notifier import (
load_notifications,
notification_mark_seen,
@ -40,12 +35,7 @@ from resolvers.reader import (
load_shouts_search,
load_shouts_unrated,
)
from resolvers.topic import (
get_topic,
get_topics_all,
get_topics_by_author,
get_topics_by_community,
)
from resolvers.topic import get_topic, get_topics_all, get_topics_by_author, get_topics_by_community
from services.triggers import events_register
events_register()

View File

@ -315,10 +315,13 @@ async def get_author_followers(_, _info, slug: str):
if isinstance(cached, str):
followers_cached = json.loads(cached)
if isinstance(followers_cached, list):
logger.debug(f"@{slug} got {len(followers_cached)} followers cached")
logger.debug(
f"@{slug} got {len(followers_cached)} followers cached"
)
for fc in followers_cached:
if fc["id"] not in followers_ids:
if fc["id"] not in followers_ids and fc["id"] != author_id:
followers.append(fc)
followers_ids.append(fc["id"])
return followers
author_follower_alias = aliased(AuthorFollower, name="af")
@ -327,12 +330,16 @@ async def get_author_followers(_, _info, slug: str):
and_(
author_follower_alias.author == author_id,
author_follower_alias.follower == Author.id,
Author.id != author_id, # exclude the author from the followers
),
)
results = get_with_stat(q)
if isinstance(results, list):
followers_ids = [r.id for r in results]
for follower in results:
if follower.id not in followers_ids:
await cache_follow_author_change(follower.dict(), author.dict())
followers_ids.append(follower.id)
logger.debug(f"@{slug} cache updated with {len(results)} followers")
return results
except Exception as exc:

View File

@ -4,15 +4,15 @@ from sqlalchemy import and_, desc, select
from sqlalchemy.orm import joinedload
from sqlalchemy.sql.functions import coalesce
from orm.author import Author
from orm.rating import is_negative, is_positive
from orm.reaction import Reaction, ReactionKind
from orm.shout import Shout, ShoutAuthor, ShoutTopic
from orm.topic import Topic
from orm.author import Author
from resolvers.follower import reactions_follow, reactions_unfollow
from resolvers.stat import get_with_stat
from services.auth import login_required
from services.cache import cache_topic, cache_author
from services.cache import cache_author, cache_topic
from services.db import local_session
from services.diff import apply_diff, get_diff
from services.logger import root_logger as logger
@ -99,7 +99,7 @@ async def get_shouts_drafts(_, info):
.group_by(Shout.id)
)
shouts = [shout for [shout] in session.execute(q).unique()]
return { "shouts": shouts }
return {"shouts": shouts}
@mutation.field("create_shout")

View File

@ -8,12 +8,7 @@ from sqlalchemy.orm import aliased
from sqlalchemy.sql import not_
from orm.author import Author
from orm.notification import (
Notification,
NotificationAction,
NotificationEntity,
NotificationSeen,
)
from orm.notification import Notification, NotificationAction, NotificationEntity, NotificationSeen
from orm.shout import Shout
from services.auth import login_required
from services.db import local_session

View File

@ -1,6 +1,8 @@
import subprocess
from granian.constants import Interfaces
from granian.server import Granian
import subprocess
from services.logger import root_logger as logger
from settings import PORT

View File

@ -1,9 +1,9 @@
import json
from orm.topic import TopicFollower
from services.db import local_session
from services.encoders import CustomJSONEncoder
from services.rediscache import redis
from services.db import local_session
DEFAULT_FOLLOWS = {
"topics": [],
@ -64,10 +64,9 @@ async def cache_author(author: dict):
# author not found in the list, so add the new author with the updated stat field
followed_author_followers.append(author)
await redis.execute(
"SET", f"author:{author_id}:followers", json.dumps(
followed_author_followers,
cls=CustomJSONEncoder
)
"SET",
f"author:{author_id}:followers",
json.dumps(followed_author_followers, cls=CustomJSONEncoder),
)
@ -138,7 +137,6 @@ async def cache_follow_author_change(follower: dict, author: dict, is_insert=Tru
return followers
async def cache_topic(topic_dict: dict):
# update stat all field for followers' caches in <topics> list
followers = (

View File

@ -30,8 +30,12 @@ async def handle_author_follower_change(
[follower] = get_with_stat(follower_query)
if follower and author:
await cache_author(author.dict())
await cache_follows(follower.dict(), "author", author.dict(), is_insert) # cache_author(follower_dict) inside
await cache_follow_author_change(follower.dict(), author.dict(), is_insert) # cache_author(follower_dict) inside
await cache_follows(
follower.dict(), "author", author.dict(), is_insert
) # cache_author(follower_dict) inside
await cache_follow_author_change(
follower.dict(), author.dict(), is_insert
) # cache_author(follower_dict) inside
async def handle_topic_follower_change(

View File

@ -7,12 +7,7 @@ from typing import Dict
# ga
from google.analytics.data_v1beta import BetaAnalyticsDataClient
from google.analytics.data_v1beta.types import (
DateRange,
Dimension,
Metric,
RunReportRequest,
)
from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest
from orm.author import Author
from orm.shout import Shout, ShoutAuthor, ShoutTopic