fix lazy loading
This commit is contained in:
parent
608881b5d8
commit
e9e2f25f4d
|
|
@ -12,6 +12,7 @@ from app.core._blockchain.ton.toncenter import toncenter
|
||||||
from app.core._utils.send_status import send_status
|
from app.core._utils.send_status import send_status
|
||||||
from app.core.logger import make_log
|
from app.core.logger import make_log
|
||||||
from app.core.models import UserContent, KnownTelegramMessage, ServiceConfig
|
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.models.node_storage import StoredContent
|
||||||
from app.core._utils.resolve_content import resolve_content
|
from app.core._utils.resolve_content import resolve_content
|
||||||
from app.core.models.wallet_connection import WalletConnection
|
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:
|
if not licensed_content:
|
||||||
make_log("Indexer", f"Licensed content not found: {new_license.content_id}", level="error")
|
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"
|
assert content_metadata, "No content metadata found"
|
||||||
|
|
||||||
if not (licensed_content.owner_address == new_license.owner_address):
|
if not (licensed_content.owner_address == new_license.owner_address):
|
||||||
try:
|
try:
|
||||||
user = new_license.user
|
user = await session.get(User, new_license.user_id)
|
||||||
if user.telegram_id and licensed_content:
|
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(
|
await (Wrapped_CBotChat(memory._client_telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)).send_content(
|
||||||
session, licensed_content
|
session, licensed_content
|
||||||
|
|
@ -79,7 +80,7 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
|
||||||
WalletConnection.invalidated == False
|
WalletConnection.invalidated == False
|
||||||
).order_by(desc(WalletConnection.id))
|
).order_by(desc(WalletConnection.id))
|
||||||
)).scalars().first()
|
)).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:
|
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)
|
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(
|
await wallet_owner_bot.send_message(
|
||||||
|
|
@ -217,7 +218,7 @@ async def indexer_loop(memory, platform_found: bool, seqno: int) -> [bool, int]:
|
||||||
user = None
|
user = None
|
||||||
if user_wallet_connection:
|
if user_wallet_connection:
|
||||||
encrypted_stored_content.user_id = user_wallet_connection.user_id
|
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:
|
if user:
|
||||||
user_uploader_wrapper = Wrapped_CBotChat(memory._telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)
|
user_uploader_wrapper = Wrapped_CBotChat(memory._telegram_bot, chat_id=user.telegram_id, user=user, db_session=session)
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,16 @@ class StoredContent(AlchemyBase, AudioContentMixin):
|
||||||
with open(metadata_content.filepath, 'r') as f:
|
with open(metadata_content.filepath, 'r') as f:
|
||||||
return json.loads(f.read())
|
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
|
@classmethod
|
||||||
def from_cid(cls, db_session, content_id):
|
def from_cid(cls, db_session, content_id):
|
||||||
if isinstance(content_id, str):
|
if isinstance(content_id, str):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue