Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

fix session load time #629

Merged
merged 1 commit into from
May 17, 2024
Merged

fix session load time #629

merged 1 commit into from
May 17, 2024

Conversation

sbasan
Copy link
Contributor

@sbasan sbasan commented May 3, 2024

Pull Request summary:

Use cached_property for api and endpoints containers in ManagerSession class.
Import required modules on-demand.

This PR needs follow up: APIContainer and APIEndpointContainer classes properties also needs to utilize this trick so items are imported only when first used to further optimize load time.

Description of changes:

Because APIContainer and APIEndpointContainer incorporate large number of pydantic models it could take long time before everything is imported for first time.

# content of test.py
from catalystwan.session import ManagerSession
session = ManagerSession(url="", username="", password="")
python -m cProfile test.py

Before:

6390615 function calls (5533081 primitive calls) in 2.241 seconds

After:

408929 function calls (392369 primitive calls) in 0.246 seconds

Checklist:

  • Make sure to run pre-commit before committing changes
  • Make sure all checks have passed
  • PR description is clear and comprehensive
  • Mentioned the issue that this PR solves (if applicable)
  • Make sure you test the changes

@sbasan sbasan changed the title api and endpoints containers as cached properties fix session load time May 3, 2024
@sbasan sbasan force-pushed the fix/session-load-time branch from fda8f1f to 67a3c0b Compare May 3, 2024 08:09
@sbasan sbasan requested a review from smialy May 6, 2024 13:12
@sbasan sbasan force-pushed the fix/session-load-time branch from 67a3c0b to e265fce Compare May 6, 2024 13:13
@sbasan sbasan force-pushed the fix/session-load-time branch from e265fce to 54720f0 Compare May 17, 2024 08:33
@sbasan sbasan marked this pull request as ready for review May 17, 2024 08:35
@sbasan sbasan requested a review from JimOverholt May 17, 2024 08:39
@sbasan sbasan force-pushed the fix/session-load-time branch from 54720f0 to dc286af Compare May 17, 2024 08:52
self._platform_version: str = ""
self._api_version: Version
self._state: ManagerSessionState = ManagerSessionState.OPERATIVE
self.restart_timeout: int = 1200
self.polling_requests_timeout: int = 10
self._validate_responses = validate_responses

@cached_property
Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool

@sbasan sbasan merged commit 3b7b6e0 into main May 17, 2024
10 checks passed
@sbasan sbasan deleted the fix/session-load-time branch May 17, 2024 19:49
sbasan added a commit that referenced this pull request May 20, 2024
* fix model_validators with before mode

* remove print statement

* skip not validated policy definitions and lists during collect

* fix literal default value

* add version field in UX1/UX2Config models

* fix bgp parcel enveloping alias path

* use UX2ConfigPushResult as push return value for push_ux2_config

* allow disabling of response validation against pydantic model

* include original cause and info from server in ManagerHTTPError

* fix: request and response must be provided as kwargs

* introduce find method for DataSequence (#627)

* api and endpoints containers as cached properties (#629)

* fix typo

* hotfix ManagerErrorInfo model

* do not collect templates for specific device types

* bump version, generate ENDPOINTS.md

* fix OspfArea model
sbasan added a commit that referenced this pull request Jun 11, 2024
* Revert "Dev/rebase migration" (#513)

* Fix find_template_values when vipValue not present (#520)

* clear cookies on login, bump minor (#532)

* [Fix] validation software timeout (#534)

* clear cookies on login, bump minor

* fix validation value

---------

Co-authored-by: sbasan <[email protected]>

* fix log message level for request exceptions

* bump patch version

* disable relogin flag during logout (#537)

* fix typo (#542)

* update deprecated github actions (#544)

* update deprecated github actions

* fix type error

* Simplify conditional logic. Add comments. Create new field in cisco vpn feature template model. (new in 20.14)

* Transfer to cisco-open repository (#1)

* use new uri, add missing copyright, bump version, regenerate ENDPOINTS.md

* regenerate endpoints after rebase

* define codeowners

* .github codeowners

* usernames in codeowners

* remove pydantic v1 models (#10)

* remove pydantic v1 models

* fix problems

* bump minor version

* Fix DeviceData types (#13)

* Fix DeviceData types

* Bump sdk version

* Update README.md

* Update README.md

* Update README.md

* Update README.md

* Add default None values to the Tier model (#16)

* Fix: admintech wait (#17)

* version check and model update for user

* admin tech - wait for file ready

* get token

* correct logic

* Add default None values to the Tier model (#16)

---------

Co-authored-by: Nikhil <[email protected]>
Co-authored-by: PrzeG <[email protected]>

* fix admintech, generate endpoints md for new release (#18)

* generate endpoints md

* fix admintech api and unittests

* Update README.md

* Update versions_utils.py

```
--------------------------------------------------
nExpress_mtt.test_nExpress_mtt_verify_provider_software_upgrade_data
--------------------------------------------------
verify_provider_software_upgrade_vmanage(PROVIDER)
[PASS] "All VManages updated correctly."

verify_provider_software_upgrade_vbond(PROVIDER)
[PASS] "All VBonds updated correctly."

verify_set_default_partition_for_vbond(PROVIDER)
[PASS] "Successfully set the default version for partition."
```

* Update versions_utils.py

* Update versions_utils.py

* Update versions_utils.py

* Release 0.33.3

* server_info

* monitoring

* monitoring

* tests

* fix tags field for DeviceDetailsResponse

* unit-test

* enhance modesl for configuration_settings

* don't use Union

* allow centralized cli policy creation

* fix for groupId for get_list_of_installed_devices

* Release/0.33.4

* url_monitoring initial commit

* GET Monitoring Security Policy Device List (#45)

* GET Monitoring Security Policy Device List

* Update security_policy.py

* Update security_policy.py

* Update test_monitoring_security_policy.py

* Add files via upload

* Delete endpoints/endpoints_container.py

* Delete endpoints/monitoring/security_policy.py

* Delete models/security_policy.py

* Delete tests/test_monitoring_security_policy.py

* Add files via upload

* Add files via upload

* Update security_policy.py

* Delete catalystwan/models/security_policy.py

* Update endpoints_container.py

* Update endpoints_container.py

* Update security_policy.py

* Update security_policy.py

* Update test_monitoring_security_policy.py

* Update security_policy.py

* Update security_policy.py

* Adding api support for Lxc virutal image Upgrade,Activate and Delete action

* Ran black and flake8 on change files

* Fixing poetry check error from pre-commit

* Fixing errors from pre-commit

* Release/0.33.5

* fix pre-commit for python 3.12 (#614)

* Update README.md

* Update README.md

* allow disabling of response validation against pydantic model

* rename property, remove print from tests

* unit tests added for url_monitoring

* updated the imports

* updated import sort

* Fix sequence creation when payload is None. Use Field instead of conint

* Revert breaking change

* Fix value for field examples

* include original cause and info from server in ManagerHTTPError

* fix: request and response must be provided as kwargs

* Bump version to 0.33.6

* introduce find method for DataSequence (#627)

* api and endpoints containers as cached properties (#629)

* hotfix ManagerErrorInfo model

* Fix find_template_values to return device variables in correct structure

* Delete if condition with pass

* Fix Issue646 Not content in response

* restore tenant model validate during login

* bump release version

* alarms-20.15

* 0.33.8

* Validate XSRF token returned by server

In same case this token can be login page and raise incorrect error in future login flow.

* Add copy and deepcopy

* Remove 2023 license

* merge and fix confilcts

---------

Co-authored-by: PrzeG <[email protected]>
Co-authored-by: cicharka <[email protected]>
Co-authored-by: JimOverholt <[email protected]>
Co-authored-by: Jakub Krajewski <[email protected]>
Co-authored-by: Nikhil <[email protected]>
Co-authored-by: Piotr Smialkowski <[email protected]>
Co-authored-by: Jim Overholt <[email protected]>
Co-authored-by: acichon <[email protected]>
Co-authored-by: nikhilkp93 <[email protected]>
Co-authored-by: Renuka Mohan Channapatna (rchannap) <[email protected]>
Co-authored-by: Robert Mooy <[email protected]>
Co-authored-by: Surendran Palanimuthu <[email protected]>
Co-authored-by: renukavinay <[email protected]>
Co-authored-by: Jakub Krajewski <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants