Skip to content

Commit

Permalink
Add commit suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Jan 16, 2025
1 parent da5bd1e commit d326bca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
20 changes: 9 additions & 11 deletions app/datasources/db/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from datetime import datetime, timezone
from typing import AsyncGenerator, AsyncIterator, cast
from typing import AsyncIterator, Self, cast

from sqlalchemy import DateTime, Row
from sqlalchemy import DateTime
from sqlmodel import (
JSON,
Column,
Expand Down Expand Up @@ -80,7 +80,7 @@ async def get_or_create(
:param name: The name to check or create.
:param url: The URL to check or create.
:return: A tuple containing the AbiSource object and a boolean indicating
whether it was created (True) or already exists (False).
whether it was created `True` or already exists `False`.
"""
query = select(cls).where(cls.name == name, cls.url == url)
results = await session.exec(query)
Expand Down Expand Up @@ -168,7 +168,7 @@ async def get_or_create_abi(
:param relevance:
:param source_id:
:return: A tuple containing the Abi object and a boolean indicating
whether it was created (True) or already exists (False).
whether it was created `True` or already exists `False`.
"""
if abi := await cls.get_abi(session, abi_json):
return abi, False
Expand Down Expand Up @@ -218,7 +218,7 @@ def get_contracts_query(
Return a statement to get contracts for the provided address and chain_id
:param address:
:param chain_ids: list of chain_ids, None for all chains
:param chain_ids: list of chain_ids, `None` for all chains
:return:
"""
query = select(cls).where(cls.address == address)
Expand Down Expand Up @@ -286,7 +286,7 @@ async def get_abi_by_contract_address(
@classmethod
async def get_contracts_without_abi(
cls, session: AsyncSession, max_retries: int = 0
) -> AsyncGenerator["Contract", None]:
) -> AsyncIterator[Self]:
"""
Fetches contracts without an ABI and fewer retries than max_retries,
streaming results in batches to reduce memory usage for large datasets.
Expand All @@ -299,24 +299,22 @@ async def get_contracts_without_abi(
"""
query = (
select(cls)
.where(cls.abi_id == None) # noqa: E711
.where(cls.abi_id.isnot(None)) # type: ignore
.where(cls.fetch_retries <= max_retries)
)
result = await session.stream(query)
async for (contract,) in result:
yield contract

@classmethod
async def get_proxy_contracts(
cls, session: AsyncSession
) -> AsyncGenerator["Contract", None]:
async def get_proxy_contracts(cls, session: AsyncSession) -> AsyncIterator[Self]:
"""
Return all the contracts with implementation address, so proxy contracts.
:param session:
:return:
"""
query = select(cls).where(cls.implementation != None) # noqa: E711
query = select(cls).where(cls.implementation.isnot(None)) # type: ignore
result = await session.stream(query)
async for (contract,) in result:
yield contract
4 changes: 2 additions & 2 deletions app/tests/datasources/db/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from app.datasources.db.database import database_session
from app.datasources.db.models import Abi, AbiSource, Contract, Project
from app.services.contract_metadata_service import (
ClientSource,
ContractMetadataService,
ContractSource,
EnhancedContractMetadata,
)

Expand Down Expand Up @@ -184,7 +184,7 @@ async def test_get_proxy_contracts(self, session: AsyncSession):
enhanced_contract_metadata = EnhancedContractMetadata(
address=random_address,
metadata=etherscan_proxy_metadata_mock,
source=ClientSource.ETHERSCAN,
source=ContractSource.ETHERSCAN,
chain_id=1,
)
result = await ContractMetadataService.process_contract_metadata(
Expand Down

0 comments on commit d326bca

Please sign in to comment.