Skip to content

Commit df93bc2

Browse files
committed
Initialize testing object only once in lifetime.
Indeed, before this patch, we were rebuilding the testing object over and over. From now on, we only do it once then just pick up the necessary one - after it was initialized.
1 parent f792b6a commit df93bc2

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

PyFunceble/cli/processes/workers/tester.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class TesterWorker(WorkerBase):
8585
testing_object: Optional[CheckerBase] = None
8686

8787
known_testing_objects: dict = {}
88+
initiated_testing_objects: dict = {}
8889

8990
def __post_init__(self) -> None:
9091
self.continue_dataset = (
@@ -110,6 +111,18 @@ def __post_init__(self) -> None:
110111
},
111112
}
112113

114+
self.initiated_testing_objects = {
115+
"SYNTAX": {"domain": None, "url": None},
116+
"AVAILABILITY": {
117+
"domain": None,
118+
"url": None,
119+
},
120+
"REPUTATION": {
121+
"domain": None,
122+
"url": None,
123+
},
124+
}
125+
113126
return super().__post_init__()
114127

115128
@staticmethod
@@ -168,31 +181,25 @@ def _init_testing_object(
168181
When the given subject type is unknown.
169182
"""
170183

171-
if checker_type in self.known_testing_objects:
172-
if subject_type in self.known_testing_objects[checker_type]:
173-
# Yes, we initialize before returning!
174-
175-
if not isinstance(
176-
self.known_testing_objects[checker_type][subject_type],
177-
type(self.testing_object),
178-
):
179-
self.testing_object = self.known_testing_objects[checker_type][
180-
subject_type
181-
](db_session=self.db_session)
182-
183-
# We want to always check the syntax first (ONLY UNDER THE CLI)
184-
self.testing_object.set_do_syntax_check_first(
185-
not bool(
186-
PyFunceble.storage.CONFIGURATION.cli_testing.local_network
187-
)
188-
)
184+
if checker_type not in self.known_testing_objects:
185+
raise ValueError(f"<testing_mode> ({checker_type!r}) is unknown.")
186+
187+
if subject_type not in self.known_testing_objects[checker_type]:
188+
raise ValueError(f"<subject_type> ({subject_type!r}) is unknown.")
189189

190-
return self.testing_object
190+
if not self.initiated_testing_objects[checker_type][subject_type]:
191+
self.initiated_testing_objects[checker_type][
192+
subject_type
193+
] = self.known_testing_objects[checker_type][subject_type](
194+
db_session=self.db_session
195+
).set_do_syntax_check_first(
196+
# We want to always check the syntax first (ONLY UNDER THE CLI)
197+
not bool(PyFunceble.storage.CONFIGURATION.cli_testing.local_network)
198+
)
191199

192-
return None
200+
self.testing_object = self.initiated_testing_objects[checker_type][subject_type]
193201

194-
raise ValueError(f"<subject_type> ({subject_type!r}) is unknown.")
195-
raise ValueError(f"<testing_mode> ({checker_type!r}) is unknown.")
202+
return self.testing_object
196203

197204
def target(self, consumed: dict) -> Optional[Tuple[Any, ...]]:
198205
"""

0 commit comments

Comments
 (0)