Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Device get_question_by_id, and always fetch template before data to ensure we do not get None #60

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mikelgg93
Copy link
Member

Added Device.get_question_by_id(), and always fetch template before data to ensure we do not get None.

@@ -248,6 +252,14 @@ async def post_template_data(
logger.debug(f"[{self}.get_template_data] Send data's template: {result}")
return result

async def get_question_by_id(self, question_id: T.Union[str, UUID]):
self.template_definition = await self.get_template()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of making a new http call every time someone calls this function, I'd first check if the question id is in the current self.template_definition and only update it if that's not the case.

Copy link
Member Author

@mikelgg93 mikelgg93 Jul 8, 2024

Choose a reason for hiding this comment

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

async def get_question_by_id(self, question_id: T.Union[str, UUID]):
        item = (
            self.template_definition.get_question_by_id(question_id)
            if self.template_definition
            else None
        )

        if item:
            return item

        old_template = self.template_definition if self.template_definition else None

        await self.get_template()

        if (
            self.template_definition is not None
            and self.template_definition is not old_template
        ):
            return self.template_definition.get_question_by_id(question_id)

        return None

Something like this? where we check first if the question_id is in the template already set, if it is not set or not found (assuming you changed it in between), we fetch it and then try again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants