Skip to content

Commit

Permalink
Optimize FirewallWrapper instantiation in fds.py
Browse files Browse the repository at this point in the history
Moved the FirewallWrapper instance creation outside of the for loop in the fds.py file. This change avoids creating multiple instances of FirewallWrapper unnecessarily. Instead, a single instance is created and reused, optimizing resource usage.
  • Loading branch information
dvershinin committed Feb 29, 2024
1 parent c1e690f commit c5b5340
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions fds/fds.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ def block_region(region):
"""
countries = Countries()
fw = FirewallWrapper() # Create a single instance outside the loop
for country in countries:
if country.data['region'] == region:
action_block(country.name, reload=False)
action_block(country.name, reload=False, fw=fw)


def action_block(ip_or_country_name, ipset_name=None, reload=True):
def action_block(ip_or_country_name, ipset_name=None, reload=True, fw=None):
# FD
fw = FirewallWrapper()
if fw is None:
fw = FirewallWrapper()
# CF
from cds.CloudflareWrapper import CloudflareWrapper
cw = CloudflareWrapper()
Expand Down

0 comments on commit c5b5340

Please sign in to comment.