dev@locazia: fix indexer
This commit is contained in:
parent
7537dc6a69
commit
a6c34e732f
|
|
@ -13,6 +13,7 @@ from app.core.logger import make_log
|
||||||
from app.core.models.node_storage import StoredContent
|
from app.core.models.node_storage import StoredContent
|
||||||
from app.core.models.wallet_connection import WalletConnection
|
from app.core.models.wallet_connection import WalletConnection
|
||||||
from app.core.storage import db_session
|
from app.core.storage import db_session
|
||||||
|
import os
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -114,31 +115,36 @@ async def indexer_loop(platform_found: bool, seqno: int) -> [bool, int]:
|
||||||
StoredContent.hash == item_content_hash_str,
|
StoredContent.hash == item_content_hash_str,
|
||||||
# StoredContent.type.like("local%")
|
# StoredContent.type.like("local%")
|
||||||
).first()
|
).first()
|
||||||
is_duplicate = encrypted_stored_content.type.startswith("onchain") and encrypted_stored_content.onchain_index == item_index
|
if encrypted_stored_content:
|
||||||
if encrypted_stored_content and not is_duplicate:
|
is_duplicate = encrypted_stored_content.type.startswith("onchain") \
|
||||||
if encrypted_stored_content.type.startswith('local'):
|
and encrypted_stored_content.onchain_index != item_index
|
||||||
encrypted_stored_content.type = "onchain/content" + ("_unknown" if not (encrypted_stored_content.key_id is None) else "")
|
if not is_duplicate:
|
||||||
encrypted_stored_content.onchain_index = item_index
|
if encrypted_stored_content.type.startswith('local'):
|
||||||
encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1)
|
encrypted_stored_content.type = "onchain/content" + (
|
||||||
if user_wallet_connection:
|
"_unknown" if not (encrypted_stored_content.key_id is None) else "")
|
||||||
encrypted_stored_content.user_id = user_wallet_connection.user_id
|
encrypted_stored_content.onchain_index = item_index
|
||||||
# elif encrypted_stored_content.type.startswith('onchain') and encrypted_stored_content.onchain_index == item_index:
|
encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1)
|
||||||
# encrypted_stored_content.type = "onchain/content" + ("_unknown" if not (encrypted_stored_content.key_id is None) else "")
|
if user_wallet_connection:
|
||||||
# encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1)
|
encrypted_stored_content.user_id = user_wallet_connection.user_id
|
||||||
# if user_wallet_connection:
|
# elif encrypted_stored_content.type.startswith('onchain') and encrypted_stored_content.onchain_index == item_index:
|
||||||
# encrypted_stored_content.user_id = user_wallet_connection.user_id
|
# encrypted_stored_content.type = "onchain/content" + ("_unknown" if not (encrypted_stored_content.key_id is None) else "")
|
||||||
else:
|
# encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1)
|
||||||
make_log("Indexer", f"Item already indexed and not local: {item_content_hash_str}", level="error")
|
# if user_wallet_connection:
|
||||||
|
# encrypted_stored_content.user_id = user_wallet_connection.user_id
|
||||||
|
else:
|
||||||
|
make_log("Indexer", f"Item already indexed and not local: {item_content_hash_str}", level="error")
|
||||||
|
return platform_found, seqno
|
||||||
|
|
||||||
|
encrypted_stored_content.updated = datetime.now()
|
||||||
|
if encrypted_stored_content.meta != item_metadata_packed:
|
||||||
|
encrypted_stored_content.meta = item_metadata_packed
|
||||||
|
|
||||||
|
session.commit()
|
||||||
return platform_found, seqno
|
return platform_found, seqno
|
||||||
|
else:
|
||||||
encrypted_stored_content.updated = datetime.now()
|
item_metadata_packed['copied_from'] = encrypted_stored_content.id
|
||||||
if encrypted_stored_content.meta != item_metadata_packed:
|
item_metadata_packed['copied_from_cid'] = encrypted_stored_content.cid.serialize_v2()
|
||||||
encrypted_stored_content.meta = item_metadata_packed
|
item_content_hash_str = f"IGNORED_DUPLICATE_{b58encode(os.urandom(30)).decode()}" # check this for vulnerability
|
||||||
|
|
||||||
session.commit()
|
|
||||||
return platform_found, seqno
|
|
||||||
|
|
||||||
item_metadata_packed['copied_from'] = encrypted_stored_content.id if encrypted_stored_content else None
|
|
||||||
|
|
||||||
onchain_stored_content = StoredContent(
|
onchain_stored_content = StoredContent(
|
||||||
type="onchain/content_unknown",
|
type="onchain/content_unknown",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue