migration-wip

This commit is contained in:
tonyrewin 2022-08-12 18:17:04 +03:00
parent 9c60318919
commit 5859a4db40
4 changed files with 10 additions and 4 deletions

View File

@ -301,4 +301,4 @@ def migrate():
print('[migration] usage: python migrate.py <command>')
print('[migration] commands: mongodb, bson, all, all mdx, - <slug>')
migrate()
if __name__ == '__main__': migrate()

View File

@ -89,7 +89,6 @@ def migrate(entry, storage):
r['updatedAt'] = date_parse(entry['updatedAt']) if 'updatedAt' in entry else ts
if entry.get('published'):
r['publishedAt'] = date_parse(entry.get('publishedAt', OLD_DATE))
if r['publishedAt'] == OLD_DATE: r['publishedAt'] = ts
if 'deletedAt' in entry: r['deletedAt'] = date_parse(entry['deletedAt'])
# topics

View File

@ -67,6 +67,7 @@ class User(Base):
id = 0,
email = "welcome@discours.io",
username = "welcome@discours.io",
name = "Дискурс",
slug = "discours",
userpic = 'https://discours.io/images/logo-mini.svg',
)

View File

@ -2,10 +2,11 @@
import asyncio
from datetime import datetime, timedelta
from sqlalchemy import and_, desc, func, select
from sqlalchemy.orm import selectinload
from sqlalchemy.orm import selectinload, joinedload
from base.orm import local_session
from orm.reaction import Reaction
from orm.shout import Shout
from orm.topic import Topic
from services.zine.reactions import ReactionsStorage
from services.stat.viewed import ViewedByDay
@ -36,12 +37,16 @@ class ShoutsCache:
async def prepare_recent_all():
with local_session() as session:
stmt = select(Shout).\
options(selectinload(Shout.authors), selectinload(Shout.topics)).\
options(
selectinload(Shout.authors),
selectinload(Shout.topics)
).\
order_by(desc("createdAt")).\
limit(ShoutsCache.limit)
shouts = []
for row in session.execute(stmt):
shout = row.Shout
# shout.topics = [t.slug for t in shout.topics]
shout.rating = await ReactionsStorage.shout_rating(shout.slug) or 0
shouts.append(shout)
async with ShoutsCache.lock:
@ -64,6 +69,7 @@ class ShoutsCache:
shouts = []
for row in session.execute(stmt):
shout = row.Shout
# shout.topics = [t.slug for t in shout.topics]
shout.rating = await ReactionsStorage.shout_rating(shout.slug) or 0
shouts.append(shout)
async with ShoutsCache.lock: