Skip to content

Optimize fill_form by removing redundant get_template calls#375

Open
Lochit-Vinay wants to merge 1 commit intofireform-core:mainfrom
Lochit-Vinay:fix/redundant-get-template
Open

Optimize fill_form by removing redundant get_template calls#375
Lochit-Vinay wants to merge 1 commit intofireform-core:mainfrom
Lochit-Vinay:fix/redundant-get-template

Conversation

@Lochit-Vinay
Copy link
Copy Markdown

@Lochit-Vinay Lochit-Vinay commented Mar 29, 2026

This PR addresses inefficiency in the fill_form endpoint by removing redundant database calls.
Solves Issue #374

Summary

Optimized the fill_form endpoint by removing redundant calls to get_template().

Problem

The current implementation calls get_template() twice:

  • Once to check if the template exists
  • Again to fetch the template data
if not get_template(db, form.template_id):
    raise AppError("Template not found", status_code=404)

fetched_template = get_template(db, form.template_id)

This results in unnecessary database queries and reduced efficiency.

Solution

Refactored the code to call get_template() only once and reuse the result:

fetched_template = get_template(db, form.template_id)

if not fetched_template:
    raise AppError("Template not found", status_code=404)

Benefits

  • Eliminates redundant database calls
  • Improves performance
  • Enhances code readability and maintainability

Additional Notes

This optimization reduces database load and improves endpoint efficiency, especially under repeated usage.
This change does not alter functionality but improves the efficiency of the endpoint by avoiding duplicate queries.

I’d be happy to extend this optimization to similar patterns across the codebase if needed.

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.

1 participant