code review, all authors query restored

This commit is contained in:
Igor Lobanov
2022-11-18 01:38:29 +01:00
parent 7969f67c67
commit aee83c31b5
5 changed files with 133 additions and 89 deletions

12
services/zine/authors.py Normal file
View File

@@ -0,0 +1,12 @@
from base.orm import local_session
from orm.user import User
from orm.shout import ShoutAuthor
class AuthorsStorage:
@staticmethod
async def get_all_authors():
with local_session() as session:
query = session.query(User).join(ShoutAuthor)
result = query.all()
return result

View File

@@ -6,7 +6,6 @@ from orm.shout import ShoutAuthor, Shout
class ShoutAuthorStorage:
authors_by_shout = {}
shouts_by_author = {}
lock = asyncio.Lock()
period = 30 * 60 # sec
@@ -17,10 +16,7 @@ class ShoutAuthorStorage:
for sa in sas:
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.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
async def get_authors(shout):