Skip to content

perf: eliminate copy.deepcopy from core state management and notifications#616

Open
wahh3b-lgtm wants to merge 2 commits into
PasarGuard:devfrom
wahh3b-lgtm:pr-3-deepcopy-v2
Open

perf: eliminate copy.deepcopy from core state management and notifications#616
wahh3b-lgtm wants to merge 2 commits into
PasarGuard:devfrom
wahh3b-lgtm:pr-3-deepcopy-v2

Conversation

@wahh3b-lgtm

Copy link
Copy Markdown

Changes

  • CoreManager (app/core/manager.py): State snapshots use dict()/list() shallow copies. Getters return deepcopy() only for AbstractCore objects to prevent live state mutation
  • HostManager (app/core/hosts.py): Uses dict() instead of deepcopy() for host state snapshots
  • Subscription (app/subscription/share.py): Uses model_copy(deep=True) for nested tls_config and transport_config to prevent mutating cached host data
  • Discord notifications (8 files): Replaced 36 copy.deepcopy() calls with {**template, "footer": dict(template["footer"])} dict spread pattern

Files Changed

  • app/core/manager.py
  • app/core/hosts.py
  • app/subscription/share.py
  • app/notification/discord/admin.py
  • app/notification/discord/admin_role.py
  • app/notification/discord/core.py
  • app/notification/discord/group.py
  • app/notification/discord/host.py
  • app/notification/discord/node.py
  • app/notification/discord/user.py
  • app/notification/discord/user_template.py

Verification

  • Ruff lint + format pass
  • 13/13 tests pass

…tions

- CoreManager: use dict/list shallow copies for state snapshots, deepcopy for AbstractCore objects in getters
- HostManager: use dict() instead of deepcopy for host state snapshots
- Subscription share: use model_copy(deep=True) for nested tls_config/transport_config to avoid mutating cached hosts
- Discord notifications: replace copy.deepcopy with dict spread + footer clone for 36 notification template copies
@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 962cfd18-06fa-4e28-afe7-a485ff76a34a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread app/core/hosts.py Outdated
wireguard_reserved=reserved,
wireguard_dns=dns,
fragment_settings=host.fragment_settings.model_dump() if host.fragment_settings else None,
noise_settings=host.noise_settings.model_dump() if host.noise_settings else None,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😐

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol yeah, caused by my autistic ai agent, i will fix it rn

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😐

fixed :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants