recent-commented
This commit is contained in:
parent
c479b12e65
commit
a8313d1324
|
@ -40,6 +40,7 @@ from resolvers.topics import (
|
||||||
topics_by_community,
|
topics_by_community,
|
||||||
topics_all,
|
topics_all,
|
||||||
)
|
)
|
||||||
|
|
||||||
from resolvers.zine import (
|
from resolvers.zine import (
|
||||||
get_shout_by_slug,
|
get_shout_by_slug,
|
||||||
follow,
|
follow,
|
||||||
|
@ -49,6 +50,8 @@ from resolvers.zine import (
|
||||||
top_overall,
|
top_overall,
|
||||||
recent_published,
|
recent_published,
|
||||||
recent_all,
|
recent_all,
|
||||||
|
recent_commented,
|
||||||
|
recent_reacted,
|
||||||
top_viewed,
|
top_viewed,
|
||||||
shouts_by_authors,
|
shouts_by_authors,
|
||||||
shouts_by_topics,
|
shouts_by_topics,
|
||||||
|
@ -72,6 +75,8 @@ __all__ = [
|
||||||
"get_top_authors",
|
"get_top_authors",
|
||||||
# zine
|
# zine
|
||||||
"recent_published",
|
"recent_published",
|
||||||
|
"recent_commented",
|
||||||
|
"recent_reacted",
|
||||||
"recent_all",
|
"recent_all",
|
||||||
"shouts_by_topics",
|
"shouts_by_topics",
|
||||||
"shouts_by_authors",
|
"shouts_by_authors",
|
||||||
|
|
|
@ -64,6 +64,12 @@ async def recent_reacted(_, _info, offset, limit):
|
||||||
return ShoutsCache.recent_reacted[offset : offset + limit]
|
return ShoutsCache.recent_reacted[offset : offset + limit]
|
||||||
|
|
||||||
|
|
||||||
|
@query.field("recentCommented")
|
||||||
|
async def recent_commented(_, _info, offset, limit):
|
||||||
|
async with ShoutsCache.lock:
|
||||||
|
return ShoutsCache.recent_commented[offset : offset + limit]
|
||||||
|
|
||||||
|
|
||||||
@query.field("getShoutBySlug")
|
@query.field("getShoutBySlug")
|
||||||
async def get_shout_by_slug(_, info, slug):
|
async def get_shout_by_slug(_, info, slug):
|
||||||
all_fields = [
|
all_fields = [
|
||||||
|
|
|
@ -236,7 +236,8 @@ type Query {
|
||||||
topOverall(offset: Int!, limit: Int!): [Shout]!
|
topOverall(offset: Int!, limit: Int!): [Shout]!
|
||||||
topCommented(offset: Int!, limit: Int!): [Shout]!
|
topCommented(offset: Int!, limit: Int!): [Shout]!
|
||||||
recentPublished(offset: Int!, limit: Int!): [Shout]! # homepage
|
recentPublished(offset: Int!, limit: Int!): [Shout]! # homepage
|
||||||
recentReacted(offset: Int!, limit: Int!): [Shout]! # test
|
recentReacted(offset: Int!, limit: Int!): [Shout]!
|
||||||
|
recentCommented(offset: Int!, limit: Int!): [Shout]!
|
||||||
recentAll(offset: Int!, limit: Int!): [Shout]!
|
recentAll(offset: Int!, limit: Int!): [Shout]!
|
||||||
|
|
||||||
# reactons
|
# reactons
|
||||||
|
|
|
@ -36,6 +36,7 @@ class ShoutsCache:
|
||||||
recent_published = []
|
recent_published = []
|
||||||
recent_all = []
|
recent_all = []
|
||||||
recent_reacted = []
|
recent_reacted = []
|
||||||
|
recent_commented = []
|
||||||
top_month = []
|
top_month = []
|
||||||
top_overall = []
|
top_overall = []
|
||||||
top_viewed = []
|
top_viewed = []
|
||||||
|
@ -102,7 +103,7 @@ class ShoutsCache:
|
||||||
selectinload(Shout.authors),
|
selectinload(Shout.authors),
|
||||||
selectinload(Shout.topics),
|
selectinload(Shout.topics),
|
||||||
)
|
)
|
||||||
.where(and_(bool(Shout.publishedAt), Shout.slug.in_(list(reacted_slugs))))
|
.where(Shout.slug.in_(list(reacted_slugs)))
|
||||||
.filter(not bool(Shout.deletedAt))
|
.filter(not bool(Shout.deletedAt))
|
||||||
.group_by(Shout.slug)
|
.group_by(Shout.slug)
|
||||||
.order_by(Shout.publishedAt)
|
.order_by(Shout.publishedAt)
|
||||||
|
@ -113,6 +114,33 @@ class ShoutsCache:
|
||||||
ShoutsCache.recent_reacted = shouts
|
ShoutsCache.recent_reacted = shouts
|
||||||
print("[zine.cache] %d recently reacted shouts " % len(shouts))
|
print("[zine.cache] %d recently reacted shouts " % len(shouts))
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
async def prepare_recent_commented():
|
||||||
|
with local_session() as session:
|
||||||
|
reactions = session.query(Reaction).order_by(Reaction.createdAt).limit(ShoutsCache.limit)
|
||||||
|
commented_slugs = set([])
|
||||||
|
for r in reactions:
|
||||||
|
if bool(r.body):
|
||||||
|
commented_slugs.add(r.shout)
|
||||||
|
shouts = await prepare_shouts(
|
||||||
|
session,
|
||||||
|
(
|
||||||
|
select(Shout)
|
||||||
|
.options(
|
||||||
|
selectinload(Shout.authors),
|
||||||
|
selectinload(Shout.topics),
|
||||||
|
)
|
||||||
|
.where(Shout.slug.in_(list(commented_slugs)))
|
||||||
|
.filter(not bool(Shout.deletedAt))
|
||||||
|
.group_by(Shout.slug)
|
||||||
|
.order_by(Shout.publishedAt)
|
||||||
|
.limit(ShoutsCache.limit)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
async with ShoutsCache.lock:
|
||||||
|
ShoutsCache.recent_commented = shouts
|
||||||
|
print("[zine.cache] %d recently commented shouts " % len(shouts))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def prepare_top_overall():
|
async def prepare_top_overall():
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
|
@ -240,6 +268,7 @@ class ShoutsCache:
|
||||||
await ShoutsCache.prepare_recent_published()
|
await ShoutsCache.prepare_recent_published()
|
||||||
await ShoutsCache.prepare_recent_all()
|
await ShoutsCache.prepare_recent_all()
|
||||||
await ShoutsCache.prepare_recent_reacted()
|
await ShoutsCache.prepare_recent_reacted()
|
||||||
|
await ShoutsCache.prepare_recent_commented()
|
||||||
|
|
||||||
await ShoutsCache.prepare_by_author()
|
await ShoutsCache.prepare_by_author()
|
||||||
await ShoutsCache.prepare_by_topic()
|
await ShoutsCache.prepare_by_topic()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user