Skip to content

Commit b585df0

Browse files
committed
refactor: cache parsed results
1 parent da8db9c commit b585df0

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

pytest_splunk_addon/standard_lib/addon_parser/eventtype_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def __init__(self, splunk_app_path: str):
4242

4343
@property
4444
def eventtypes(self) -> Optional[Dict]:
45+
if self._eventtypes is not None:
46+
return self._eventtypes
4547
eventtypes_conf_path = os.path.join(
4648
self.splunk_app_path, "default", "eventtypes.conf"
4749
)
4850
LOGGER.info("Parsing eventtypes.conf")
4951
self._conf_parser.read(eventtypes_conf_path)
50-
result = self._conf_parser.item_dict()
51-
return result if result else None
52+
self._eventtypes = self._conf_parser.item_dict()
53+
return self._eventtypes if self._eventtypes else None
5254

5355
def get_eventtypes(self) -> Optional[Generator]:
5456
"""

pytest_splunk_addon/standard_lib/addon_parser/savedsearches_parser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def __init__(self, splunk_app_path: str):
4242

4343
@property
4444
def savedsearches(self) -> Optional[Dict]:
45+
if self._savedsearches is not None:
46+
return self._savedsearches
4547
savedsearches_conf_path = os.path.join(
4648
self.splunk_app_path, "default", "savedsearches.conf"
4749
)
4850
LOGGER.info("Parsing savedsearches.conf")
4951
self._conf_parser.read(savedsearches_conf_path)
50-
result = self._conf_parser.item_dict()
51-
return result if result else None
52+
self._savedsearches = self._conf_parser.item_dict()
53+
return self._savedsearches if self._savedsearches else None
5254

5355
def get_savedsearches(self) -> Optional[Generator]:
5456
"""

pytest_splunk_addon/standard_lib/addon_parser/tags_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def __init__(self, splunk_app_path: str):
4343
def tags(self) -> Optional[Dict]:
4444
if self._tags is not None:
4545
return self._tags
46-
LOGGER.info("Parsing tags.conf")
4746
tags_conf_path = os.path.join(self.splunk_app_path, "default", "tags.conf")
47+
LOGGER.info("Parsing tags.conf")
4848
self._conf_parser.read(tags_conf_path)
4949
self._tags = self._conf_parser.item_dict()
5050
return self._tags if self._tags else None

0 commit comments

Comments
 (0)