fixed-topicstat-erorrs
This commit is contained in:
parent
1fc46bb450
commit
a585f2a8e0
|
@ -1,5 +1,6 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
from base.orm import local_session
|
from base.orm import local_session
|
||||||
|
from orm.shout import Shout
|
||||||
from services.stat.reacted import ReactedStorage
|
from services.stat.reacted import ReactedStorage
|
||||||
from services.stat.viewed import ViewedStorage
|
from services.stat.viewed import ViewedStorage
|
||||||
from services.zine.shoutauthor import ShoutAuthorStorage
|
from services.zine.shoutauthor import ShoutAuthorStorage
|
||||||
|
@ -26,16 +27,23 @@ class TopicStat:
|
||||||
async def load_stat(session):
|
async def load_stat(session):
|
||||||
self = TopicStat
|
self = TopicStat
|
||||||
shout_topics = session.query(ShoutTopic).all()
|
shout_topics = session.query(ShoutTopic).all()
|
||||||
|
print('[stat.topics] shout topics amount', len(shout_topics))
|
||||||
for shout_topic in shout_topics:
|
for shout_topic in shout_topics:
|
||||||
|
|
||||||
|
# shouts by topics
|
||||||
topic = shout_topic.topic
|
topic = shout_topic.topic
|
||||||
shout = shout_topic.shout
|
shout = shout_topic.shout
|
||||||
if not self.shouts_by_topic.get(topic):
|
sss = set(self.shouts_by_topic.get(topic, []))
|
||||||
self.shouts_by_topic[topic] = []
|
shout = session.query(Shout).where(Shout.slug == shout).first()
|
||||||
self.shouts_by_topic[topic].append(shout)
|
sss.union([shout, ])
|
||||||
|
self.shouts_by_topic[topic] = list(sss)
|
||||||
|
|
||||||
|
# authors by topics
|
||||||
authors = await ShoutAuthorStorage.get_authors(shout)
|
authors = await ShoutAuthorStorage.get_authors(shout)
|
||||||
if not self.authors_by_topic.get(topic):
|
aaa = set(self.authors_by_topic.get(topic, []))
|
||||||
self.authors_by_topic[topic] = []
|
aaa.union(authors)
|
||||||
self.authors_by_topic[topic] = unique(self.authors_by_topic[topic] + authors)
|
self.authors_by_topic[topic] = list(aaa)
|
||||||
|
|
||||||
print("[stat.topics] authors sorted")
|
print("[stat.topics] authors sorted")
|
||||||
print("[stat.topics] shouts sorted")
|
print("[stat.topics] shouts sorted")
|
||||||
|
|
||||||
|
@ -44,10 +52,9 @@ class TopicStat:
|
||||||
for flw in followings:
|
for flw in followings:
|
||||||
topic = flw.topic
|
topic = flw.topic
|
||||||
user = flw.follower
|
user = flw.follower
|
||||||
if topic in self.followers_by_topic:
|
if topic not in self.followers_by_topic:
|
||||||
|
self.followers_by_topic[topic] = []
|
||||||
self.followers_by_topic[topic].append(user)
|
self.followers_by_topic[topic].append(user)
|
||||||
else:
|
|
||||||
self.followers_by_topic[topic] = [user, ]
|
|
||||||
print("[stat.topics] followers sorted")
|
print("[stat.topics] followers sorted")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -38,8 +38,8 @@ class ShoutsCache:
|
||||||
select(Shout)
|
select(Shout)
|
||||||
.options(selectinload(Shout.authors), selectinload(Shout.topics))
|
.options(selectinload(Shout.authors), selectinload(Shout.topics))
|
||||||
.where(bool(Shout.publishedAt))
|
.where(bool(Shout.publishedAt))
|
||||||
|
.group_by(Shout.slug)
|
||||||
.order_by(desc("publishedAt"))
|
.order_by(desc("publishedAt"))
|
||||||
.order_by(desc("createdAt"))
|
|
||||||
.limit(ShoutsCache.limit)
|
.limit(ShoutsCache.limit)
|
||||||
))
|
))
|
||||||
async with ShoutsCache.lock:
|
async with ShoutsCache.lock:
|
||||||
|
@ -52,6 +52,8 @@ class ShoutsCache:
|
||||||
shouts = await prepare_shouts(session, (
|
shouts = await prepare_shouts(session, (
|
||||||
select(Shout)
|
select(Shout)
|
||||||
.options(selectinload(Shout.authors), selectinload(Shout.topics))
|
.options(selectinload(Shout.authors), selectinload(Shout.topics))
|
||||||
|
.where(and_(bool(Shout.publishedAt), bool(Reaction.deletedAt)))
|
||||||
|
.group_by(Shout.slug)
|
||||||
.order_by(desc("createdAt"))
|
.order_by(desc("createdAt"))
|
||||||
.limit(ShoutsCache.limit)
|
.limit(ShoutsCache.limit)
|
||||||
))
|
))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user