This commit is contained in:
parent
e61db5d6e5
commit
e0a5c654d8
|
@ -1,10 +1,12 @@
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
|
from sqlalchemy import JSON, Boolean, Column, ForeignKey, Integer, String
|
||||||
# from sqlalchemy_utils import TSVectorType
|
|
||||||
|
|
||||||
from services.db import Base
|
from services.db import Base
|
||||||
|
|
||||||
|
# from sqlalchemy_utils import TSVectorType
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class AuthorRating(Base):
|
class AuthorRating(Base):
|
||||||
__tablename__ = "author_rating"
|
__tablename__ = "author_rating"
|
||||||
|
|
|
@ -11,12 +11,7 @@ from resolvers.author import ( # search_authors,
|
||||||
)
|
)
|
||||||
from resolvers.community import get_communities_all, get_community
|
from resolvers.community import get_communities_all, get_community
|
||||||
from resolvers.editor import create_shout, delete_shout, update_shout
|
from resolvers.editor import create_shout, delete_shout, update_shout
|
||||||
from resolvers.follower import (
|
from resolvers.follower import follow, get_shout_followers, get_topic_followers, unfollow
|
||||||
follow,
|
|
||||||
get_shout_followers,
|
|
||||||
get_topic_followers,
|
|
||||||
unfollow,
|
|
||||||
)
|
|
||||||
from resolvers.notifier import (
|
from resolvers.notifier import (
|
||||||
load_notifications,
|
load_notifications,
|
||||||
notification_mark_seen,
|
notification_mark_seen,
|
||||||
|
@ -40,12 +35,7 @@ from resolvers.reader import (
|
||||||
load_shouts_search,
|
load_shouts_search,
|
||||||
load_shouts_unrated,
|
load_shouts_unrated,
|
||||||
)
|
)
|
||||||
from resolvers.topic import (
|
from resolvers.topic import get_topic, get_topics_all, get_topics_by_author, get_topics_by_community
|
||||||
get_topic,
|
|
||||||
get_topics_all,
|
|
||||||
get_topics_by_author,
|
|
||||||
get_topics_by_community,
|
|
||||||
)
|
|
||||||
from services.triggers import events_register
|
from services.triggers import events_register
|
||||||
|
|
||||||
events_register()
|
events_register()
|
||||||
|
|
|
@ -315,10 +315,13 @@ async def get_author_followers(_, _info, slug: str):
|
||||||
if isinstance(cached, str):
|
if isinstance(cached, str):
|
||||||
followers_cached = json.loads(cached)
|
followers_cached = json.loads(cached)
|
||||||
if isinstance(followers_cached, list):
|
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:
|
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.append(fc)
|
||||||
|
followers_ids.append(fc["id"])
|
||||||
return followers
|
return followers
|
||||||
|
|
||||||
author_follower_alias = aliased(AuthorFollower, name="af")
|
author_follower_alias = aliased(AuthorFollower, name="af")
|
||||||
|
@ -327,12 +330,16 @@ async def get_author_followers(_, _info, slug: str):
|
||||||
and_(
|
and_(
|
||||||
author_follower_alias.author == author_id,
|
author_follower_alias.author == author_id,
|
||||||
author_follower_alias.follower == Author.id,
|
author_follower_alias.follower == Author.id,
|
||||||
|
Author.id != author_id, # exclude the author from the followers
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
results = get_with_stat(q)
|
results = get_with_stat(q)
|
||||||
if isinstance(results, list):
|
if isinstance(results, list):
|
||||||
|
followers_ids = [r.id for r in results]
|
||||||
for follower in results:
|
for follower in results:
|
||||||
|
if follower.id not in followers_ids:
|
||||||
await cache_follow_author_change(follower.dict(), author.dict())
|
await cache_follow_author_change(follower.dict(), author.dict())
|
||||||
|
followers_ids.append(follower.id)
|
||||||
logger.debug(f"@{slug} cache updated with {len(results)} followers")
|
logger.debug(f"@{slug} cache updated with {len(results)} followers")
|
||||||
return results
|
return results
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
|
|
@ -4,15 +4,15 @@ from sqlalchemy import and_, desc, select
|
||||||
from sqlalchemy.orm import joinedload
|
from sqlalchemy.orm import joinedload
|
||||||
from sqlalchemy.sql.functions import coalesce
|
from sqlalchemy.sql.functions import coalesce
|
||||||
|
|
||||||
|
from orm.author import Author
|
||||||
from orm.rating import is_negative, is_positive
|
from orm.rating import is_negative, is_positive
|
||||||
from orm.reaction import Reaction, ReactionKind
|
from orm.reaction import Reaction, ReactionKind
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
from orm.topic import Topic
|
from orm.topic import Topic
|
||||||
from orm.author import Author
|
|
||||||
from resolvers.follower import reactions_follow, reactions_unfollow
|
from resolvers.follower import reactions_follow, reactions_unfollow
|
||||||
from resolvers.stat import get_with_stat
|
from resolvers.stat import get_with_stat
|
||||||
from services.auth import login_required
|
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.db import local_session
|
||||||
from services.diff import apply_diff, get_diff
|
from services.diff import apply_diff, get_diff
|
||||||
from services.logger import root_logger as logger
|
from services.logger import root_logger as logger
|
||||||
|
@ -99,7 +99,7 @@ async def get_shouts_drafts(_, info):
|
||||||
.group_by(Shout.id)
|
.group_by(Shout.id)
|
||||||
)
|
)
|
||||||
shouts = [shout for [shout] in session.execute(q).unique()]
|
shouts = [shout for [shout] in session.execute(q).unique()]
|
||||||
return { "shouts": shouts }
|
return {"shouts": shouts}
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("create_shout")
|
@mutation.field("create_shout")
|
||||||
|
|
|
@ -8,12 +8,7 @@ from sqlalchemy.orm import aliased
|
||||||
from sqlalchemy.sql import not_
|
from sqlalchemy.sql import not_
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from orm.notification import (
|
from orm.notification import Notification, NotificationAction, NotificationEntity, NotificationSeen
|
||||||
Notification,
|
|
||||||
NotificationAction,
|
|
||||||
NotificationEntity,
|
|
||||||
NotificationSeen,
|
|
||||||
)
|
|
||||||
from orm.shout import Shout
|
from orm.shout import Shout
|
||||||
from services.auth import login_required
|
from services.auth import login_required
|
||||||
from services.db import local_session
|
from services.db import local_session
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from granian.constants import Interfaces
|
from granian.constants import Interfaces
|
||||||
from granian.server import Granian
|
from granian.server import Granian
|
||||||
import subprocess
|
|
||||||
from services.logger import root_logger as logger
|
from services.logger import root_logger as logger
|
||||||
from settings import PORT
|
from settings import PORT
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from orm.topic import TopicFollower
|
from orm.topic import TopicFollower
|
||||||
|
from services.db import local_session
|
||||||
from services.encoders import CustomJSONEncoder
|
from services.encoders import CustomJSONEncoder
|
||||||
from services.rediscache import redis
|
from services.rediscache import redis
|
||||||
from services.db import local_session
|
|
||||||
|
|
||||||
DEFAULT_FOLLOWS = {
|
DEFAULT_FOLLOWS = {
|
||||||
"topics": [],
|
"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
|
# author not found in the list, so add the new author with the updated stat field
|
||||||
followed_author_followers.append(author)
|
followed_author_followers.append(author)
|
||||||
await redis.execute(
|
await redis.execute(
|
||||||
"SET", f"author:{author_id}:followers", json.dumps(
|
"SET",
|
||||||
followed_author_followers,
|
f"author:{author_id}:followers",
|
||||||
cls=CustomJSONEncoder
|
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
|
return followers
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async def cache_topic(topic_dict: dict):
|
async def cache_topic(topic_dict: dict):
|
||||||
# update stat all field for followers' caches in <topics> list
|
# update stat all field for followers' caches in <topics> list
|
||||||
followers = (
|
followers = (
|
||||||
|
|
|
@ -30,8 +30,12 @@ async def handle_author_follower_change(
|
||||||
[follower] = get_with_stat(follower_query)
|
[follower] = get_with_stat(follower_query)
|
||||||
if follower and author:
|
if follower and author:
|
||||||
await cache_author(author.dict())
|
await cache_author(author.dict())
|
||||||
await cache_follows(follower.dict(), "author", author.dict(), is_insert) # cache_author(follower_dict) inside
|
await cache_follows(
|
||||||
await cache_follow_author_change(follower.dict(), author.dict(), is_insert) # cache_author(follower_dict) inside
|
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(
|
async def handle_topic_follower_change(
|
||||||
|
|
|
@ -7,12 +7,7 @@ from typing import Dict
|
||||||
|
|
||||||
# ga
|
# ga
|
||||||
from google.analytics.data_v1beta import BetaAnalyticsDataClient
|
from google.analytics.data_v1beta import BetaAnalyticsDataClient
|
||||||
from google.analytics.data_v1beta.types import (
|
from google.analytics.data_v1beta.types import DateRange, Dimension, Metric, RunReportRequest
|
||||||
DateRange,
|
|
||||||
Dimension,
|
|
||||||
Metric,
|
|
||||||
RunReportRequest,
|
|
||||||
)
|
|
||||||
|
|
||||||
from orm.author import Author
|
from orm.author import Author
|
||||||
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
from orm.shout import Shout, ShoutAuthor, ShoutTopic
|
||||||
|
|
Loading…
Reference in New Issue
Block a user