mariadb -> postgres

This commit is contained in:
user committed 2025-08-22 14:04:21 +03:00
1 parent 21964fa986
commit e51bb86dc0
36 files changed
+650 -464

No files matched your search

+24 -23
View File
@@ -10,18 +10,21 @@ from httpx import AsyncClient
class WalletMixin:
def wallet_connection(self, db_session):
return db_session.query(WalletConnection).filter(
WalletConnection.user_id == self.id,
WalletConnection.invalidated == False
).order_by(WalletConnection.created.desc()).first()
async def wallet_connection_async(self, db_session):
from sqlalchemy import select, and_, desc
result = await db_session.execute(
select(WalletConnection)
.where(and_(WalletConnection.user_id == self.id, WalletConnection.invalidated == False))
.order_by(WalletConnection.created.desc())
)
return result.scalars().first()
def wallet_address(self, db_session):
wallet_connection = self.wallet_connection(db_session)
return wallet_connection.wallet_address if wallet_connection else None
async def wallet_address_async(self, db_session):
wc = await self.wallet_connection_async(db_session)
return wc.wallet_address if wc else None
async def scan_owned_user_content(self, db_session):
user_wallet_address = self.wallet_address(db_session)
user_wallet_address = await self.wallet_address_async(db_session)
async def get_nft_items_list():
try:
@@ -40,9 +43,8 @@ class WalletMixin:
item_address = Address(nft_item['address']).to_string(1, 1, 1)
owner_address = Address(nft_item['owner']['address']).to_string(1, 1, 1)
user_content = db_session.query(UserContent).filter(
UserContent.onchain_address == item_address
).first()
from sqlalchemy import select
user_content = (await db_session.execute(select(UserContent).where(UserContent.onchain_address == item_address))).scalars().first()
if user_content:
continue
@@ -57,18 +59,18 @@ class WalletMixin:
created=datetime.now(),
meta={},
user_id=self.id,
wallet_connection_id=self.wallet_connection(db_session).id,
wallet_connection_id=(await self.wallet_connection_async(db_session)).id,
status="active"
)
db_session.add(user_content)
db_session.commit()
await db_session.commit()
make_log(self, f"New onchain NFT found: {item_address}", level='info')
async def ____scan_owned_user_content(self, db_session):
page_id = -1
page_size = 100
have_next_page = True
user_wallet_address = self.wallet_address(db_session)
user_wallet_address = await self.wallet_address_async(db_session)
while have_next_page:
page_id += 1
nfts_list = await toncenter.get_nft_items(limit=100, offset=page_id * page_size, owner_address=user_wallet_address)
@@ -81,9 +83,8 @@ class WalletMixin:
item_address = Address(nft_item['address']).to_string(1, 1, 1)
owner_address = Address(nft_item['owner_address']).to_string(1, 1, 1)
user_content = db_session.query(UserContent).filter(
UserContent.onchain_address == item_address
).first()
from sqlalchemy import select
user_content = (await db_session.execute(select(UserContent).where(UserContent.onchain_address == item_address))).scalars().first()
if user_content:
continue
@@ -105,11 +106,11 @@ class WalletMixin:
'metadata_uri': nft_content,
},
user_id=self.id,
wallet_connection_id=self.wallet_connection(db_session).id,
wallet_connection_id=(await self.wallet_connection_async(db_session)).id,
status="active"
)
db_session.add(user_content)
db_session.commit()
await db_session.commit()
make_log(self, f"New onchain NFT found: {item_address}", level='info')
except BaseException as e:
@@ -122,6 +123,6 @@ class WalletMixin:
except BaseException as e:
make_log(self, f"Error while scanning user content: {e}", level='error')
return self.db_session.query(UserContent).filter(
UserContent.user_id == self.id
).offset(offset).limit(limit).all()
from sqlalchemy import select
result = await db_session.execute(select(UserContent).where(UserContent.user_id == self.id).offset(offset).limit(limit))
return result.scalars().all()