dev@locazia: fix indexer

This commit is contained in:
user 2024-03-10 00:44:06 +03:00
parent 7537dc6a69
commit a6c34e732f
1 changed files with 30 additions and 24 deletions

View File

@ -13,6 +13,7 @@ from app.core.logger import make_log
from app.core.models.node_storage import StoredContent
from app.core.models.wallet_connection import WalletConnection
from app.core.storage import db_session
import os
import traceback
@ -114,10 +115,13 @@ async def indexer_loop(platform_found: bool, seqno: int) -> [bool, int]:
StoredContent.hash == item_content_hash_str,
# StoredContent.type.like("local%")
).first()
is_duplicate = encrypted_stored_content.type.startswith("onchain") and encrypted_stored_content.onchain_index == item_index
if encrypted_stored_content and not is_duplicate:
if encrypted_stored_content:
is_duplicate = encrypted_stored_content.type.startswith("onchain") \
and encrypted_stored_content.onchain_index != item_index
if not is_duplicate:
if encrypted_stored_content.type.startswith('local'):
encrypted_stored_content.type = "onchain/content" + ("_unknown" if not (encrypted_stored_content.key_id is None) else "")
encrypted_stored_content.type = "onchain/content" + (
"_unknown" if not (encrypted_stored_content.key_id is None) else "")
encrypted_stored_content.onchain_index = item_index
encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1)
if user_wallet_connection:
@ -137,8 +141,10 @@ async def indexer_loop(platform_found: bool, seqno: int) -> [bool, int]:
session.commit()
return platform_found, seqno
item_metadata_packed['copied_from'] = encrypted_stored_content.id if encrypted_stored_content else None
else:
item_metadata_packed['copied_from'] = encrypted_stored_content.id
item_metadata_packed['copied_from_cid'] = encrypted_stored_content.cid.serialize_v2()
item_content_hash_str = f"IGNORED_DUPLICATE_{b58encode(os.urandom(30)).decode()}" # check this for vulnerability
onchain_stored_content = StoredContent(
type="onchain/content_unknown",