From e9e2f25f4df47f9dc0bd51123602eb46a956cbf1 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 25 Aug 2025 14:35:20 +0300 Subject: [PATCH] fix lazy loading --- app/core/background/indexer_service.py | 9 +++++---- app/core/models/node_storage.py | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/core/background/indexer_service.py b/app/core/background/indexer_service.py index 47c075a..af37852 100644 --- a/app/core/background/indexer_service.py +++ b/app/core/background/indexer_service.py @@ -12,6 +12,7 @@ from app.core._blockchain.ton.toncenter import toncenter from app.core._utils.send_status import send_status from app.core.logger import make_log from app.core.models import UserContent, KnownTelegramMessage, ServiceConfig +from app.core.models.user import User from app.core.models.node_storage import StoredContent from app.core._utils.resolve_content import resolve_content from app.core.models.wallet_connection import WalletConnection @@ -62,12 +63,12 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]: if not licensed_content: make_log("Indexer", f"Licensed content not found: {new_license.content_id}", level="error") - content_metadata = licensed_content.metadata_json(session) + content_metadata = await licensed_content.metadata_json_async(session) assert content_metadata, "No content metadata found" if not (licensed_content.owner_address == new_license.owner_address): try: - user = new_license.user + user = await session.get(User, new_license.user_id) if user.telegram_id and licensed_content: await (Wrapped_CBotChat(memory._client_telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)).send_content( session, licensed_content @@ -79,7 +80,7 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]: WalletConnection.invalidated == False ).order_by(desc(WalletConnection.id)) )).scalars().first() - wallet_owner_user = wallet_owner_connection.user + wallet_owner_user = await session.get(User, wallet_owner_connection.user_id) if wallet_owner_connection else None if wallet_owner_user.telegram_id: wallet_owner_bot = Wrapped_CBotChat(memory._telegram_bot, chat_id=wallet_owner_user.telegram_id, user=wallet_owner_user, db_session=session) await wallet_owner_bot.send_message( @@ -217,7 +218,7 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]: user = None if user_wallet_connection: encrypted_stored_content.user_id = user_wallet_connection.user_id - user = user_wallet_connection.user + user = await session.get(User, user_wallet_connection.user_id) if user: user_uploader_wrapper = Wrapped_CBotChat(memory._telegram_bot, chat_id=user.telegram_id, user=user, db_session=session) diff --git a/app/core/models/node_storage.py b/app/core/models/node_storage.py index 2cd6e59..cec6a67 100644 --- a/app/core/models/node_storage.py +++ b/app/core/models/node_storage.py @@ -171,6 +171,16 @@ class StoredContent(AlchemyBase, AudioContentMixin): with open(metadata_content.filepath, 'r') as f: return json.loads(f.read()) + async def metadata_json_async(self, db_session): + metadata_cid = self.meta.get('metadata_cid') + if not metadata_cid: + return None + metadata_content = await StoredContent.from_cid_async(db_session, metadata_cid) + import aiofiles + async with aiofiles.open(metadata_content.filepath, 'r') as f: + data = await f.read() + return json.loads(data) + @classmethod def from_cid(cls, db_session, content_id): if isinstance(content_id, str):