-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skip database calls in core.tx.load() if data list is empty (#1433)
### Summary > Describe your changes. If the list passed to load() is empty, we now return early to save time from checking indexes, generating a query string, and talking to the database. Also fixes this for AWS' resourcegroupstaggingapi sync. Since many cartography users likely have nothing in many regions, we might as well save ourselves some network and database calls. ### Checklist Provide proof that this works (this makes reviews move faster). Please perform one or more of the following: - [x] Update/add unit or integration tests. - [ ] Include a screenshot showing what the graph looked like before and after your changes. - [ ] Include console log trace showing what happened before and after your changes. If you are changing a node or relationship: - [ ] Update the [schema](https://github.com/lyft/cartography/tree/master/docs/root/modules) and [readme](https://github.com/lyft/cartography/blob/master/docs/schema/README.md). If you are implementing a new intel module: - [ ] Use the NodeSchema [data model](https://cartography-cncf.github.io/cartography/dev/writing-intel-modules.html#defining-a-node). --------- Signed-off-by: Alex Chantavy <[email protected]>
- Loading branch information
Showing
6 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from cartography.client.core.tx import load | ||
from cartography.models.core.nodes import CartographyNodeSchema | ||
|
||
|
||
def test_load_empty_dict_list(): | ||
# Setup | ||
mock_session = MagicMock() | ||
mock_schema = MagicMock(spec=CartographyNodeSchema) | ||
empty_dict_list = [] | ||
|
||
# Execute | ||
load(mock_session, mock_schema, empty_dict_list) | ||
|
||
# Assert | ||
mock_session.run.assert_not_called() # Ensure no database calls were made | ||
# Verify that ensure_indexes was not called since we short-circuit on empty list | ||
mock_session.write_transaction.assert_not_called() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters