From 079d1c85ac2d075e8293c2f30cf13be3d36de22c Mon Sep 17 00:00:00 2001 From: BoYanZh Date: Mon, 14 Jun 2021 09:30:57 +0800 Subject: [PATCH] feat: lazy loading --- joint_teapot/teapot.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/joint_teapot/teapot.py b/joint_teapot/teapot.py index 807708c..082cf51 100644 --- a/joint_teapot/teapot.py +++ b/joint_teapot/teapot.py @@ -6,10 +6,27 @@ from joint_teapot.workers import Canvas, Git, Gitea class Teapot: - def __init__(self) -> None: - self.canvas = Canvas() - self.gitea = Gitea() - self.git = Git() + _canvas = None + _gitea = None + _git = None + + @property + def canvas(self) -> Canvas: + if not self._canvas: + self._canvas = Canvas() + return self._canvas + + @property + def gitea(self) -> Gitea: + if not self._gitea: + self._gitea = Gitea() + return self._gitea + + @property + def git(self) -> Git: + if not self._git: + self._git = Git() + return self._git def create_personal_repos_for_all_canvas_students(self) -> List[str]: return self.gitea.create_personal_repos_for_canvas_students(