all authors and some logs

This commit is contained in:
tonyrewin 2022-11-17 09:25:26 +03:00
parent 43cf5ea361
commit d62342880b
4 changed files with 17 additions and 13 deletions

View File

@ -206,9 +206,10 @@ async def load_authors_by(_, info, by, limit, offset):
).order_by( ).order_by(
by.get("order") or "createdAt" by.get("order") or "createdAt"
).limit(limit).offset(offset) ).limit(limit).offset(offset)
print(aq)
authors = list(map(lambda r: r.User, session.execute(aq))) authors = list(map(lambda r: r.User, session.execute(aq)))
if by.get("stat"): if by.get("stat"):
for a in authors: for a in authors:
a.stat = await get_author_stat(a.slug) a.stat = await get_author_stat(a.slug)
authors = list(set(authors)).sort(lambda a: a["stat"].get(by.get("stat"))) authors = list(set(authors)).sort(authors, key=lambda a: a["stat"].get(by.get("stat")))
return authors return authors

View File

@ -168,22 +168,25 @@ class ReactedStorage:
self = ReactedStorage self = ReactedStorage
all_reactions = session.query(Reaction).all() all_reactions = session.query(Reaction).all()
self.modified_shouts = list(set([r.shout for r in all_reactions])) self.modified_shouts = list(set([r.shout for r in all_reactions]))
print("[stat.reacted] %d shouts with reactions loaded" % len(self.modified_shouts)) print("[stat.reacted] %d shouts with reactions" % len(self.modified_shouts))
@staticmethod @staticmethod
async def recount_changed(session): async def recount_changed(session):
self = ReactedStorage self = ReactedStorage
async with self.lock: async with self.lock:
print('[stat.reacted] recounting...') sss = list(self.modified_shouts)
for slug in list(self.modified_shouts): c = 0
for slug in sss:
siblings = session.query(Reaction).where(Reaction.shout == slug).all() siblings = session.query(Reaction).where(Reaction.shout == slug).all()
c += len(siblings)
await self.recount(siblings) await self.recount(siblings)
print("[stat.reacted] %d reactions total" % c)
print("[stat.reacted] %d shouts" % len(self.modified_shouts)) print("[stat.reacted] %d shouts" % len(self.modified_shouts))
print("[stat.reacted] %d topics" % len(self.reacted["topics"].values())) print("[stat.reacted] %d topics" % len(self.reacted["topics"].values()))
print("[stat.reacted] %d shouts" % len(self.reacted["shouts"])) print("[stat.reacted] %d shouts" % len(self.reacted["shouts"]))
print("[stat.reacted] %d authors" % len(self.reacted["authors"].values())) print("[stat.reacted] %d authors" % len(self.reacted["authors"].values()))
print("[stat.reacted] %d reactions" % len(self.reacted["reactions"])) print("[stat.reacted] %d reactions replied" % len(self.reacted["reactions"]))
self.modified_shouts = set([]) self.modified_shouts = set([])
@staticmethod @staticmethod

View File

@ -19,7 +19,7 @@ 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] shouts linked %d times" % len(shout_topics)) print("[stat.topics] %d links for shouts" % len(shout_topics))
for shout_topic in shout_topics: for shout_topic in shout_topics:
tpc = shout_topic.topic tpc = shout_topic.topic
# shouts by topics # shouts by topics
@ -34,17 +34,14 @@ class TopicStat:
[aslug, acaption] = a [aslug, acaption] = a
self.authors_by_topic[tpc][aslug] = acaption self.authors_by_topic[tpc][aslug] = acaption
print("[stat.topics] shouts indexed by %d topics" % len(self.shouts_by_topic.keys()))
print("[stat.topics] authors indexed by %d topics" % len(self.authors_by_topic.keys()))
self.followers_by_topic = {} self.followers_by_topic = {}
followings = session.query(TopicFollower).all() followings = session.query(TopicFollower).all()
print("[stat.topics] %d followings by users" % len(followings))
for flw in followings: for flw in followings:
topic = flw.topic topic = flw.topic
userslug = flw.follower userslug = flw.follower
self.followers_by_topic[topic] = self.followers_by_topic.get(topic, dict()) self.followers_by_topic[topic] = self.followers_by_topic.get(topic, dict())
self.followers_by_topic[topic][userslug] = userslug self.followers_by_topic[topic][userslug] = userslug
print("[stat.topics] followers indexed by %d topics" % len(self.followers_by_topic.keys()))
@staticmethod @staticmethod
async def get_shouts(topic): async def get_shouts(topic):

View File

@ -17,7 +17,10 @@ class ShoutAuthorStorage:
for sa in sas: for sa in sas:
self.authors_by_shout[sa.shout] = self.authors_by_shout.get(sa.shout, []) self.authors_by_shout[sa.shout] = self.authors_by_shout.get(sa.shout, [])
self.authors_by_shout[sa.shout].append([sa.user, sa.caption]) self.authors_by_shout[sa.shout].append([sa.user, sa.caption])
print("[zine.shouts] %d shouts indexed by authors" % len(self.authors_by_shout)) self.shouts_by_author[sa.user] = self.shouts_by_author.get(sa.user, [])
self.shouts_by_author[sa.user].append(sa.shout)
print("[zine.authors] %d shouts indexed by authors" % len(self.authors_by_shout))
print("[zine.authors] %d authors indexed by shouts" % len(self.shouts_by_author))
@staticmethod @staticmethod
async def get_authors(shout): async def get_authors(shout):
@ -42,7 +45,7 @@ class ShoutAuthorStorage:
with local_session() as session: with local_session() as session:
async with self.lock: async with self.lock:
await self.load(session) await self.load(session)
print("[zine.shouts] index by authors was updated") print("[zine.authors] index by authors was updated")
except Exception as err: except Exception as err:
print("[zine.shouts] error indexing by author: %s" % (err)) print("[zine.authors] error indexing by author: %s" % (err))
await asyncio.sleep(self.period) await asyncio.sleep(self.period)