diff --git a/app/core/background/indexer_service.py b/app/core/background/indexer_service.py index af2f675..8ce39db 100644 --- a/app/core/background/indexer_service.py +++ b/app/core/background/indexer_service.py @@ -114,27 +114,32 @@ async def indexer_loop(platform_found: bool, seqno: int) -> [bool, int]: StoredContent.hash == item_content_hash_str, # StoredContent.type.like("local%") ).first() - if encrypted_stored_content: - if not encrypted_stored_content.type.startswith("local"): - make_log("Indexer", f"Item already indexed, but not local: {item_content_hash_str}", level="error") + 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.type.startswith('local'): + 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: + encrypted_stored_content.user_id = user_wallet_connection.user_id + # elif encrypted_stored_content.type.startswith('onchain') 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 "") + # encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1) + # 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_meta = encrypted_stored_content.meta - make_log("Indexer", f"Item already indexed: {item_content_hash_str}", level="debug") - encrypted_stored_content.type = "onchain/content" - encrypted_stored_content.onchain_index = item_index - encrypted_stored_content.owner_address = item_owner_address.to_string(1, 1, 1) - if user_wallet_connection: - encrypted_stored_content.user_id = user_wallet_connection.user_id - - if encrypted_stored_content_meta != item_metadata_packed: + encrypted_stored_content.updated = datetime.now() + if encrypted_stored_content.meta != item_metadata_packed: encrypted_stored_content.meta = item_metadata_packed - encrypted_stored_content.updated = datetime.now() 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( type="onchain/content_unknown", hash=item_content_hash_str,