Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unused FF_HOOK_EVENTS #1026

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 13 additions & 38 deletions src/chains/signals.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
from typing import Any

from django.conf import settings
from django.db.models.signals import m2m_changed, post_delete, post_save, pre_delete
from django.dispatch import receiver

from clients.safe_client_gateway import HookEvent, flush, hook_event
from clients.safe_client_gateway import HookEvent, hook_event

from .models import Chain, Feature, GasPrice, Wallet

Expand All @@ -16,22 +15,14 @@
@receiver(post_delete, sender=Chain)
def on_chain_update(sender: Chain, instance: Chain, **kwargs: Any) -> None:
logger.info("Chain update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.id))
else:
flush()
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.id))


@receiver(post_save, sender=GasPrice)
@receiver(post_delete, sender=GasPrice)
def on_gas_price_update(sender: GasPrice, instance: GasPrice, **kwargs: Any) -> None:
logger.info("GasPrice update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
hook_event(
HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.chain.id)
)
else:
flush()
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=instance.chain.id))


# pre_delete is used because on pre_delete the model still has chains
Expand All @@ -40,12 +31,9 @@ def on_gas_price_update(sender: GasPrice, instance: GasPrice, **kwargs: Any) ->
@receiver(pre_delete, sender=Feature)
def on_feature_changed(sender: Feature, instance: Feature, **kwargs: Any) -> None:
logger.info("Feature update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
# A Feature change affects all the chains that have this feature
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))
else:
flush()
# A Feature change affects all the chains that have this feature
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))


@receiver(m2m_changed, sender=Feature.chains.through)
Expand All @@ -54,13 +42,8 @@ def on_feature_chains_changed(
) -> None:
logger.info("FeatureChains update. Triggering CGW webhook")
if action == "post_add" or action == "post_remove":
if settings.FF_HOOK_EVENTS:
for chain_id in pk_set:
hook_event(
HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id)
)
else:
flush()
for chain_id in pk_set:
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id))


# pre_delete is used because on pre_delete the model still has chains
Expand All @@ -69,12 +52,9 @@ def on_feature_chains_changed(
@receiver(pre_delete, sender=Wallet)
def on_wallet_changed(sender: Wallet, instance: Wallet, **kwargs: Any) -> None:
logger.info("Wallet update. Triggering CGW webhook")
if settings.FF_HOOK_EVENTS:
# A Wallet change affects all the chains that have this wallet
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))
else:
flush()
# A Wallet change affects all the chains that have this wallet
for chain in instance.chains.all():
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain.id))


@receiver(m2m_changed, sender=Wallet.chains.through)
Expand All @@ -83,10 +63,5 @@ def on_wallet_chains_changed(
) -> None:
logger.info("WalletChains update. Triggering CGW webhook")
if action == "post_add" or action == "post_remove":
if settings.FF_HOOK_EVENTS:
for chain_id in pk_set:
hook_event(
HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id)
)
else:
flush()
for chain_id in pk_set:
hook_event(HookEvent(type=HookEvent.Type.CHAIN_UPDATE, chain_id=chain_id))
Loading