diff --git a/auth/authenticate.py b/auth/authenticate.py index ed530aa5..4d4e651b 100644 --- a/auth/authenticate.py +++ b/auth/authenticate.py @@ -10,7 +10,7 @@ from auth.jwtcodec import JWTCodec from auth.authorize import Authorize, TokenStorage from base.exceptions import InvalidToken from orm.user import User -from storages.users import UserStorage +from services.auth.users import UserStorage from base.orm import local_session from settings import JWT_AUTH_HEADER, EMAIL_TOKEN_LIFE_SPAN diff --git a/auth/email.py b/auth/email.py index f7b1358b..9c9b7220 100644 --- a/auth/email.py +++ b/auth/email.py @@ -6,7 +6,7 @@ from settings import BACKEND_URL, MAILGUN_API_KEY, MAILGUN_DOMAIN, RESET_PWD_URL CONFIRM_EMAIL_URL, ERROR_URL_ON_FRONTEND MAILGUN_API_URL = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN) -MAILGUN_FROM = "postmaster " % (MAILGUN_DOMAIN) +MAILGUN_FROM = "discours.io " % (MAILGUN_DOMAIN) AUTH_URL = "%s/email_authorize" % (BACKEND_URL) @@ -14,7 +14,7 @@ email_templates = {"confirm_email" : "", "auth_email" : "", "reset_password_emai def load_email_templates(): for name in email_templates: - filename = "templates/%s.tmpl" % name + filename = "auth/templates/%s.tmpl" % name # TODO: check path with open(filename) as f: email_templates[name] = f.read() print("[auth.email] templates loaded") diff --git a/templates/auth_email.tmpl b/auth/templates/auth_email.tmpl similarity index 100% rename from templates/auth_email.tmpl rename to auth/templates/auth_email.tmpl diff --git a/templates/confirm_email.tmpl b/auth/templates/confirm_email.tmpl similarity index 100% rename from templates/confirm_email.tmpl rename to auth/templates/confirm_email.tmpl diff --git a/templates/reset_password_email.tmpl b/auth/templates/reset_password_email.tmpl similarity index 100% rename from templates/reset_password_email.tmpl rename to auth/templates/reset_password_email.tmpl diff --git a/base/orm.py b/base/orm.py index e9440329..22c135db 100644 --- a/base/orm.py +++ b/base/orm.py @@ -1,10 +1,8 @@ from typing import TypeVar, Any, Dict, Generic, Callable - from sqlalchemy import create_engine, Column, Integer from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session from sqlalchemy.sql.schema import Table - from settings import DB_URL if DB_URL.startswith('sqlite'): diff --git a/base/redis.py b/base/redis.py index 3ca87270..33dcc3ca 100644 --- a/base/redis.py +++ b/base/redis.py @@ -1,7 +1,6 @@ import aioredis from settings import REDIS_URL - class Redis: def __init__(self, uri=REDIS_URL): self._uri: str = uri @@ -29,29 +28,6 @@ class Redis: return await self._instance.mget(key, *keys) -async def test(): - redis = Redis() - from datetime import datetime - - await redis.connect() - await redis.execute("SET", "1-KEY1", 1) - await redis.execute("SET", "1-KEY2", 1) - await redis.execute("SET", "1-KEY3", 1) - await redis.execute("SET", "1-KEY4", 1) - await redis.execute("EXPIREAT", "1-KEY4", int(datetime.utcnow().timestamp())) - v = await redis.execute("KEYS", "1-*") - print(v) - await redis.execute("DEL", *v) - v = await redis.execute("KEYS", "1-*") - print(v) - - -if __name__ == '__main__': - import asyncio - - asyncio.run(test()) - - redis = Redis() __all__ = ['redis'] diff --git a/main.py b/main.py index 2fa79de1..9fa77251 100644 --- a/main.py +++ b/main.py @@ -12,11 +12,11 @@ from auth.email import email_authorize from base.redis import redis from base.resolvers import resolvers from resolvers.zine import ShoutsCache -from storages.viewed import ViewedStorage -# from storages.gittask import GitTask -from storages.topicstat import TopicStat -from storages.shoutauthor import ShoutAuthorStorage -from storages.reactions import ReactionsStorage +from services.stat.viewed import ViewedStorage +from services.zine.gittask import GitTask +from services.stat.topicstat import TopicStat +from services.zine.shoutauthor import ShoutAuthorStorage +from services.zine.reactions import ReactionsStorage import asyncio import_module('resolvers') @@ -34,7 +34,7 @@ async def start_up(): reaction_stat_task = asyncio.create_task(ReactionsStorage.worker()) shout_author_task = asyncio.create_task(ShoutAuthorStorage.worker()) topic_stat_task = asyncio.create_task(TopicStat.worker()) - # FIXME git_task = asyncio.create_task(GitTask.git_task_worker()) + git_task = asyncio.create_task(GitTask.git_task_worker()) async def shutdown(): await redis.disconnect() diff --git a/orm/__init__.py b/orm/__init__.py index 43d050c4..7d31e530 100644 --- a/orm/__init__.py +++ b/orm/__init__.py @@ -1,14 +1,14 @@ from orm.rbac import Operation, Resource, Permission, Role -from storages.roles import RoleStorage +from services.auth.roles import RoleStorage from orm.community import Community from orm.user import User, UserRating from orm.topic import Topic, TopicFollower from orm.notification import Notification from orm.shout import Shout from orm.reaction import Reaction -from storages.topics import TopicStorage -from storages.users import UserStorage -from storages.viewed import ViewedStorage +from services.zine.topics import TopicStorage +from services.auth.users import UserStorage +from services.stat.viewed import ViewedStorage from base.orm import Base, engine, local_session __all__ = ["User", "Role", "Operation", "Permission", \ diff --git a/orm/collection.py b/orm/collection.py new file mode 100644 index 00000000..26c5eb39 --- /dev/null +++ b/orm/collection.py @@ -0,0 +1,20 @@ +from datetime import datetime +from sqlalchemy import Column, String, ForeignKey, DateTime, JSON as JSONType +from base.orm import Base + +class ShoutCollection(Base): + __tablename__ = 'shout_collection' + + id = None + shout = Column(ForeignKey('shout.slug'), primary_key = True) + collection = Column(ForeignKey('collection.slug'), primary_key = True) + +class Collection(Base): + __tablename__ = 'collection' + + id = None + slug: str = Column(String, primary_key = True) + title: str = Column(String, nullable=False, comment="Title") + body: str = Column(String, nullable=True, comment="Body") + pic: str = Column(String, nullable=True, comment="Picture") + diff --git a/orm/reaction.py b/orm/reaction.py index 783b057e..fadb9f1c 100644 --- a/orm/reaction.py +++ b/orm/reaction.py @@ -3,7 +3,7 @@ from sqlalchemy import Column, String, ForeignKey, DateTime from base.orm import Base, local_session import enum from sqlalchemy import Enum -from storages.viewed import ViewedStorage +from services.stat.viewed import ViewedStorage class ReactionKind(enum.Enum): AGREE = 1 # +1 diff --git a/orm/shout.py b/orm/shout.py index d7eb24ed..529848a9 100644 --- a/orm/shout.py +++ b/orm/shout.py @@ -4,8 +4,8 @@ from sqlalchemy.orm import relationship from orm.user import User from orm.topic import Topic, ShoutTopic from orm.reaction import Reaction -from storages.reactions import ReactionsStorage -from storages.viewed import ViewedStorage +from services.zine.reactions import ReactionsStorage +from services.stat.viewed import ViewedStorage from base.orm import Base diff --git a/orm/user.py b/orm/user.py index 215db8ae..e7947b0d 100644 --- a/orm/user.py +++ b/orm/user.py @@ -3,7 +3,7 @@ from sqlalchemy import Column, Integer, String, ForeignKey, Boolean, DateTime, J from sqlalchemy.orm import relationship from base.orm import Base, local_session from orm.rbac import Role -from storages.roles import RoleStorage +from services.auth.roles import RoleStorage class UserNotifications(Base): __tablename__ = 'user_notifications' diff --git a/resolvers/editor.py b/resolvers/editor.py index 24c8cbba..fccf2723 100644 --- a/resolvers/editor.py +++ b/resolvers/editor.py @@ -7,7 +7,7 @@ from base.resolvers import mutation from resolvers.reactions import reactions_follow, reactions_unfollow from auth.authenticate import login_required from datetime import datetime -from storages.gittask import GitTask +from services.zine.gittask import GitTask @mutation.field("createShout") diff --git a/resolvers/feed.py b/resolvers/feed.py index ea50322c..4a78a98f 100644 --- a/resolvers/feed.py +++ b/resolvers/feed.py @@ -1,7 +1,7 @@ from auth.authenticate import login_required from base.orm import local_session -from sqlalchemy import and_, desc, query -from orm.reaction import Reaction +from base.resolvers import query +from sqlalchemy import and_, desc from orm.shout import Shout, ShoutAuthor, ShoutTopic from orm.topic import TopicFollower from orm.user import AuthorFollower diff --git a/resolvers/profile.py b/resolvers/profile.py index ae9ba49d..7f992258 100644 --- a/resolvers/profile.py +++ b/resolvers/profile.py @@ -1,5 +1,5 @@ from orm.user import User, UserRole, Role, UserRating, AuthorFollower -from storages.users import UserStorage +from services.auth.users import UserStorage from orm.shout import Shout from orm.reaction import Reaction from base.orm import local_session diff --git a/resolvers/reactions.py b/resolvers/reactions.py index f94efacf..fd1a1fe7 100644 --- a/resolvers/reactions.py +++ b/resolvers/reactions.py @@ -5,8 +5,8 @@ from orm.user import User from base.resolvers import mutation, query from auth.authenticate import login_required from datetime import datetime -from storages.reactions import ReactionsStorage -from storages.viewed import ViewedStorage +from services.zine.reactions import ReactionsStorage +from services.stat.viewed import ViewedStorage def reactions_follow(user, slug, auto=False): with local_session() as session: diff --git a/resolvers/topics.py b/resolvers/topics.py index 02ed9815..c9424008 100644 --- a/resolvers/topics.py +++ b/resolvers/topics.py @@ -1,8 +1,8 @@ from orm.topic import Topic, TopicFollower -from storages.topics import TopicStorage +from services.zine.topics import TopicStorage from orm.shout import Shout from orm.user import User -from storages.topicstat import TopicStat +from services.stat.topicstat import TopicStat from base.orm import local_session from base.resolvers import mutation, query from auth.authenticate import login_required diff --git a/resolvers/zine.py b/resolvers/zine.py index 5cf9c318..931cf369 100644 --- a/resolvers/zine.py +++ b/resolvers/zine.py @@ -2,8 +2,8 @@ from orm.shout import Shout, ShoutAuthor, ShoutTopic from orm.topic import Topic from base.orm import local_session from base.resolvers import mutation, query -from storages.shoutscache import ShoutsCache -from storages.viewed import ViewedStorage +from services.zine.shoutscache import ShoutsCache +from services.stat.viewed import ViewedStorage from resolvers.profile import author_follow, author_unfollow from resolvers.topics import topic_follow, topic_unfollow from resolvers.community import community_follow, community_unfollow diff --git a/schema.graphql b/schema.graphql index 9c31efcf..b527543b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -97,6 +97,12 @@ input CommunityInput { pic: String } +input CollectionInput { + title: String! + desc: String + pic: String +} + input TopicInput { slug: String! community: String! @@ -169,6 +175,11 @@ type Mutation { updateCommunity(community: CommunityInput!): Result! deleteCommunity(slug: String!): Result! + # collection + createCollection(collection: CollectionInput!): Result! + updateCollection(collection: CollectionInput!): Result! + deleteCollection(slug: String!): Result! + # collab inviteAuthor(author: String!, shout: String!): Result! removeAuthor(author: String!, shout: String!): Result! @@ -239,6 +250,9 @@ type Query { topicsByCommunity(community: String!): [Topic]! topicsByAuthor(author: String!): [Topic]! + # collection + getCollection(author: String!, slug: String!): Collection! + # communities getCommunity(slug: String): Community! getCommunities: [Community]! # all @@ -404,6 +418,15 @@ type Community { createdBy: User! } +type Collection { + slug: String! + title: String! + desc: String + pic: String! + createdAt: DateTime! + createdBy: User! +} + type TopicStat { shouts: Int! followers: Int! diff --git a/storages/roles.py b/services/auth/roles.py similarity index 90% rename from storages/roles.py rename to services/auth/roles.py index b7f0a19b..b3e1e43c 100644 --- a/storages/roles.py +++ b/services/auth/roles.py @@ -13,7 +13,7 @@ class RoleStorage: roles = session.query(Role).\ options(selectinload(Role.permissions)).all() self.roles = dict([(role.id, role) for role in roles]) - print('[storage.roles] %d ' % len(roles)) + print('[service.auth] %d roles' % len(roles)) @staticmethod diff --git a/storages/users.py b/services/auth/users.py similarity index 93% rename from storages/users.py rename to services/auth/users.py index 78c66c97..89393380 100644 --- a/storages/users.py +++ b/services/auth/users.py @@ -14,7 +14,7 @@ class UserStorage: options(selectinload(User.roles), selectinload(User.ratings)).all() # TODO: add shouts and reactions counters self.users = dict([(user.id, user) for user in users]) - print('[storage.users] %d ' % len(self.users)) + print('[service.auth] %d users' % len(self.users)) @staticmethod async def get_user(id): diff --git a/services/stat/reacted.py b/services/stat/reacted.py new file mode 100644 index 00000000..95711215 --- /dev/null +++ b/services/stat/reacted.py @@ -0,0 +1,126 @@ +import asyncio +from datetime import datetime +from sqlalchemy import Column, DateTime, ForeignKey, Integer +from sqlalchemy.orm.attributes import flag_modified +from base.orm import Base, local_session +from orm.reaction import ReactionKind + +class ReactedByDay(Base): + __tablename__ = "reacted_by_day" + + id = None + reaction = Column(ForeignKey("reaction.id"), primary_key = True) + shout = Column(ForeignKey('shout.slug'), primary_key=True) + reply = Column(ForeignKey('reaction.id'), primary_key=True, nullable=True) + kind = Column(ReactionKind, primary_key=True) + day = Column(DateTime, primary_key=True, default=datetime.now) + +class ReactedStorage: + reacted = { + 'shouts': { + 'total': 0, + 'today': 0, + 'month': 0, + # TODO: need an opionated metrics list + }, + 'topics': {} # TODO: get sum reactions for all shouts in topic + } + this_day_reactions = {} + to_flush = [] + period = 30*60 # sec + lock = asyncio.Lock() + + @staticmethod + def init(session): + self = ReactedStorage + reactions = session.query(ReactedByDay).all() + + for reaction in reactions: + shout = reaction.shout + value = reaction.value + if shout: + old_value = self.reacted['shouts'].get(shout, 0) + self.reacted['shouts'][shout] = old_value + value + if not shout in self.this_day_reactions: + self.this_day_reactions[shout] = reaction + this_day_reaction = self.this_day_reactions[shout] + if this_day_reaction.day < reaction.day: + self.this_day_reactions[shout] = reaction + + print('[service.reacted] watching %d shouts' % len(reactions)) + # TODO: add reactions ? + + @staticmethod + async def get_shout(shout_slug): + self = ReactedStorage + async with self.lock: + return self.reacted['shouts'].get(shout_slug, 0) + + # NOTE: this method is never called + @staticmethod + async def get_reaction(reaction_id): + self = ReactedStorage + async with self.lock: + return self.reacted['reactions'].get(reaction_id, 0) + + @staticmethod + async def inc_shout(shout_slug): + self = ReactedStorage + async with self.lock: + this_day_reaction = self.this_day_reactions.get(shout_slug) + day_start = datetime.now().replace(hour=0, minute=0, second=0) + if not this_day_reaction or this_day_reaction.day < day_start: + if this_day_reaction and getattr(this_day_reaction, "modified", False): + self.to_flush.append(this_day_reaction) + this_day_reaction = ReactedByDay.create(shout=shout_slug, value=1) + self.this_day_reactions[shout_slug] = this_day_reaction + else: + this_day_reaction.value = this_day_reaction.value + 1 + this_day_reaction.modified = True + old_value = self.reacted['shouts'].get(shout_slug, 0) + self.reacted['shotus'][shout_slug] = old_value + 1 + + @staticmethod + async def inc_reaction(shout_slug, reaction_id): + self = ReactedStorage + async with self.lock: + this_day_reaction = self.this_day_reactions.get(reaction_id) + day_start = datetime.now().replace(hour=0, minute=0, second=0) + if not this_day_reaction or this_day_reaction.day < day_start: + if this_day_reaction and getattr(this_day_reaction, "modified", False): + self.to_flush.append(this_day_reaction) + this_day_reaction = ReactedByDay.create( + shout=shout_slug, reaction=reaction_id, value=1) + self.this_day_reactions[shout_slug] = this_day_reaction + else: + this_day_reaction.value = this_day_reaction.value + 1 + this_day_reaction.modified = True + old_value = self.reacted['shouts'].get(shout_slug, 0) + self.reacted['shouts'][shout_slug] = old_value + 1 + old_value = self.reacted['reactions'].get(shout_slug, 0) + self.reacted['reaction'][reaction_id] = old_value + 1 + + @staticmethod + async def flush_changes(session): + self = ReactedStorage + async with self.lock: + for reaction in self.this_day_reactions.values(): + if getattr(reaction, "modified", False): + session.add(reaction) + flag_modified(reaction, "value") + reaction.modified = False + for reaction in self.to_flush: + session.add(reaction) + self.to_flush.clear() + session.commit() + + @staticmethod + async def worker(): + while True: + try: + with local_session() as session: + await ReactedStorage.flush_changes(session) + print("[service.reacted] service flushed changes") + except Exception as err: + print("[service.reacted] errror: %s" % (err)) + await asyncio.sleep(ReactedStorage.period) diff --git a/storages/topicstat.py b/services/stat/topicstat.py similarity index 87% rename from storages/topicstat.py rename to services/stat/topicstat.py index 3855cced..46c9d69b 100644 --- a/storages/topicstat.py +++ b/services/stat/topicstat.py @@ -1,6 +1,6 @@ import asyncio from base.orm import local_session -from storages.shoutauthor import ShoutAuthorStorage +from services.zine.shoutauthor import ShoutAuthorStorage from orm.topic import ShoutTopic, TopicFollower from typing import Dict @@ -32,8 +32,8 @@ class TopicStat: else: self.authors_by_topic[topic] = set(authors) - print('[storage.topicstat] authors sorted') - print('[storage.topicstat] shouts sorted') + print('[service.topicstat] authors sorted') + print('[service.topicstat] shouts sorted') self.followers_by_topic = {} followings = session.query(TopicFollower) @@ -44,7 +44,7 @@ class TopicStat: self.followers_by_topic[topic].append(user) else: self.followers_by_topic[topic] = [user] - print('[storage.topicstat] followers sorted') + print('[service.topicstat] followers sorted') @staticmethod async def get_shouts(topic): @@ -76,8 +76,8 @@ class TopicStat: with local_session() as session: async with self.lock: await self.load_stat(session) - print("[storage.topicstat] updated") + print("[service.topicstat] updated") except Exception as err: - print("[storage.topicstat] errror: %s" % (err)) + print("[service.topicstat] errror: %s" % (err)) await asyncio.sleep(self.period) diff --git a/storages/viewed.py b/services/stat/viewed.py similarity index 95% rename from storages/viewed.py rename to services/stat/viewed.py index cb17fd75..46700240 100644 --- a/storages/viewed.py +++ b/services/stat/viewed.py @@ -42,7 +42,7 @@ class ViewedStorage: if this_day_view.day < view.day: self.this_day_views[shout] = view - print('[storage.viewed] watching %d shouts' % len(views)) + print('[service.viewed] watching %d shouts' % len(views)) # TODO: add reactions ? @staticmethod @@ -115,7 +115,7 @@ class ViewedStorage: try: with local_session() as session: await ViewedStorage.flush_changes(session) - print("[storage.viewed] storage flushed changes") + print("[service.viewed] service flushed changes") except Exception as err: - print("[storage.viewed] errror: %s" % (err)) + print("[service.viewed] errror: %s" % (err)) await asyncio.sleep(ViewedStorage.period) diff --git a/storages/gittask.py b/services/zine/gittask.py similarity index 100% rename from storages/gittask.py rename to services/zine/gittask.py diff --git a/storages/reactions.py b/services/zine/reactions.py similarity index 90% rename from storages/reactions.py rename to services/zine/reactions.py index b96083cb..134e5dde 100644 --- a/storages/reactions.py +++ b/services/zine/reactions.py @@ -43,7 +43,7 @@ class ReactionsStorage: reactions.append(reaction) reactions.sort(key=lambda x: x.createdAt, reverse=True) async with ReactionsStorage.lock: - print("[storage.reactions] %d recently published reactions " % len(reactions)) + print("[service.reactions] %d recently published reactions " % len(reactions)) ReactionsStorage.reactions = reactions @staticmethod @@ -57,7 +57,7 @@ class ReactionsStorage: by_authors = {} async with ReactionsStorage.lock: ReactionsStorage.reactions_by_author = dict([stat for stat in by_authors]) - print("[storage.reactions] %d reacted users" % len(by_authors)) + print("[service.reactions] %d reacted users" % len(by_authors)) @staticmethod async def prepare_by_shout(session): @@ -70,7 +70,7 @@ class ReactionsStorage: by_shouts = {} async with ReactionsStorage.lock: ReactionsStorage.reactions_by_shout = dict([stat for stat in by_shouts]) - print("[storage.reactions] %d reacted shouts" % len(by_shouts)) + print("[service.reactions] %d reacted shouts" % len(by_shouts)) @staticmethod async def calc_ratings(session): @@ -147,13 +147,13 @@ class ReactionsStorage: try: with local_session() as session: await ReactionsStorage.prepare_all(session) - print("[storage.reactions] all reactions prepared") + print("[service.reactions] all reactions prepared") await ReactionsStorage.prepare_by_shout(session) - print("[storage.reactions] reactions by shouts prepared") + print("[service.reactions] reactions by shouts prepared") await ReactionsStorage.calc_ratings(session) - print("[storage.reactions] reactions ratings prepared") + print("[service.reactions] reactions ratings prepared") await ReactionsStorage.prepare_by_topic(session) - print("[storage.reactions] reactions topics prepared") + print("[service.reactions] reactions topics prepared") except Exception as err: - print("[storage.reactions] errror: %s" % (err)) + print("[service.reactions] errror: %s" % (err)) await asyncio.sleep(ReactionsStorage.period) diff --git a/storages/shoutauthor.py b/services/zine/shoutauthor.py similarity index 81% rename from storages/shoutauthor.py rename to services/zine/shoutauthor.py index b9d356cd..7858b143 100644 --- a/storages/shoutauthor.py +++ b/services/zine/shoutauthor.py @@ -20,7 +20,7 @@ class ShoutAuthorStorage: self.authors_by_shout[shout].append(user) else: self.authors_by_shout[shout] = [user] - print('[storage.shoutauthor] %d shouts ' % len(self.authors_by_shout)) + print('[service.shoutauthor] %d shouts ' % len(self.authors_by_shout)) @staticmethod async def get_authors(shout): @@ -36,7 +36,7 @@ class ShoutAuthorStorage: with local_session() as session: async with self.lock: await self.load(session) - print("[storage.shoutauthor] updated") + print("[service.shoutauthor] updated") except Exception as err: - print("[storage.shoutauthor] errror: %s" % (err)) + print("[service.shoutauthor] errror: %s" % (err)) await asyncio.sleep(self.period) \ No newline at end of file diff --git a/storages/shoutscache.py b/services/zine/shoutscache.py similarity index 89% rename from storages/shoutscache.py rename to services/zine/shoutscache.py index bcb64b71..c1e57a06 100644 --- a/storages/shoutscache.py +++ b/services/zine/shoutscache.py @@ -6,8 +6,8 @@ from sqlalchemy.orm import selectinload from base.orm import local_session from orm.reaction import Reaction from orm.shout import Shout -from storages.reactions import ReactionsStorage -from storages.viewed import ViewedByDay +from services.zine.reactions import ReactionsStorage +from services.stat.viewed import ViewedByDay class ShoutsCache: @@ -30,7 +30,7 @@ class ShoutsCache: shouts.append(shout) async with ShoutsCache.lock: ShoutsCache.recent_published = shouts - print("[storage.shoutscache] %d recently published shouts " % len(shouts)) + print("[service.shoutscache] %d recently published shouts " % len(shouts)) @staticmethod async def prepare_recent_all(): @@ -46,7 +46,7 @@ class ShoutsCache: shouts.append(shout) async with ShoutsCache.lock: ShoutsCache.recent_all = shouts - print("[storage.shoutscache] %d recently created shouts " % len(shouts)) + print("[service.shoutscache] %d recently created shouts " % len(shouts)) @staticmethod async def prepare_recent_reacted(): @@ -68,7 +68,7 @@ class ShoutsCache: shouts.append(shout) async with ShoutsCache.lock: ShoutsCache.recent_reacted = shouts - print("[storage.shoutscache] %d recently reacted shouts " % len(shouts)) + print("[service.shoutscache] %d recently reacted shouts " % len(shouts)) @staticmethod @@ -91,7 +91,7 @@ class ShoutsCache: shouts.append(shout) shouts.sort(key = lambda shout: shout.rating, reverse = True) async with ShoutsCache.lock: - print("[storage.shoutscache] %d top shouts " % len(shouts)) + print("[service.shoutscache] %d top shouts " % len(shouts)) ShoutsCache.top_overall = shouts @staticmethod @@ -112,7 +112,7 @@ class ShoutsCache: shouts.append(shout) shouts.sort(key = lambda shout: shout.rating, reverse = True) async with ShoutsCache.lock: - print("[storage.shoutscache] %d top month shouts " % len(shouts)) + print("[service.shoutscache] %d top month shouts " % len(shouts)) ShoutsCache.top_month = shouts @staticmethod @@ -133,7 +133,7 @@ class ShoutsCache: shouts.append(shout) # shouts.sort(key = lambda shout: shout.viewed, reverse = True) async with ShoutsCache.lock: - print("[storage.shoutscache] %d top viewed shouts " % len(shouts)) + print("[service.shoutscache] %d top viewed shouts " % len(shouts)) ShoutsCache.top_viewed = shouts @staticmethod @@ -146,8 +146,8 @@ class ShoutsCache: await ShoutsCache.prepare_recent_published() await ShoutsCache.prepare_recent_all() await ShoutsCache.prepare_recent_reacted() - print("[storage.shoutscache] updated") + print("[service.shoutscache] updated") except Exception as err: - print("[storage.shoutscache] error: %s" % (err)) + print("[service.shoutscache] error: %s" % (err)) raise err await asyncio.sleep(ShoutsCache.period) diff --git a/storages/topics.py b/services/zine/topics.py similarity index 93% rename from storages/topics.py rename to services/zine/topics.py index 637728ed..0f85ed7d 100644 --- a/storages/topics.py +++ b/services/zine/topics.py @@ -14,7 +14,7 @@ class TopicStorage: for topic in self.topics.values(): self.load_parents(topic) # TODO: test - print('[storage.topics] %d ' % len(self.topics.keys())) + print('[service.topics] %d ' % len(self.topics.keys())) @staticmethod def load_parents(topic):