Skip to content

Commit

Permalink
Optimize load of ERC20 addresses
Browse files Browse the repository at this point in the history
- Closes #2301
  • Loading branch information
Uxio0 committed Nov 11, 2024
1 parent a8f54d7 commit 5ac6718
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions safe_transaction_service/history/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,22 @@ class SafeContractManager(models.Manager):
def get_banned_safes(self) -> QuerySet[ChecksumAddress]:
return self.filter(banned=True).values_list("address", flat=True)

def get_safes_as_bytes(
self, newer_than: Optional[datetime.datetime] = None
) -> list[bytes]:
"""
Calculating checksum for a lot of addresses can take a lot of time. With this method we can get
them as they are stored in the database, as bytes
:return: List of Safes as bytes
"""
query = "SELECT address FROM history_safecontract"
if newer_than:
query += f" created >= {newer_than.isoformat()}"
with connection.cursor() as cursor:
cursor.execute(query)
return [address.tobytes() for (address,) in cursor.fetchall()]


class SafeContract(models.Model):
objects = SafeContractManager()
Expand Down

0 comments on commit 5ac6718

Please sign in to comment.