Skip to content

perf: cache read-heavy db queries with streamlit - #178

Merged
SharanyaAchanta merged 2 commits into
SharanyaAchanta:mainfrom
Aspect022:feature/cache-db-queries
Mar 3, 2026
Merged

perf: cache read-heavy db queries with streamlit#178
SharanyaAchanta merged 2 commits into
SharanyaAchanta:mainfrom
Aspect022:feature/cache-db-queries

Conversation

@Aspect022

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Read-heavy database query functions like get_all_mappings() and get_categories() executed a SQLite lookup directly on every UI re-render, leading to excessive I/O overhead and UI lag.

What changes are included in this PR?

  • Streamlit Caching: Wrapped all repetitive read query functions in engine/db.py (e.g. get_mapping, get_all_mappings, get_categories, get_mapping_count, get_metadata) with @st.cache_data(ttl=3600).
  • Cache Invalidation: Added an internal _clear_db_cache() helper to forcefully clear the st.cache_data object whenever mutation functions occur (like insert_mapping, update_mapping, migrate_from_json, or restore_database).

Are these changes tested?

Yes, existing pytest integration and database utility tests passed and correctly handled the added caching logic.

Are there any user-facing changes?

Noticeable improvements in overall application performance and responsiveness, due to minimizing database queries across component renders. No functional changes were made to endpoints or structures.

@github-actions

Copy link
Copy Markdown

Thanks for creating a PR for your Issue! ☺️

We'll review it as soon as possible.
In the meantime, please double-check the file changes and ensure that all commits are accurate.

If there are any unresolved review comments, feel free to resolve them. 🙌🏼

@centiceron centiceron added the On hold Temporary "on hold" status for maintainence label Feb 27, 2026
@SharanyaAchanta

Copy link
Copy Markdown
Owner

Hey, thanks for the PRs! I was caught up with other merges yesterday. Since today is the final day, I’m wrapping things up. I see some checks are failing now—if you can resolve them quickly, let me know. If not, no worries at all, thanks for your contribution!

@Aspect022

Copy link
Copy Markdown
Contributor Author

@SharanyaAchantai have made the changes can youcheck it out!

@SharanyaAchanta
SharanyaAchanta merged commit 097777d into SharanyaAchanta:main Mar 3, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Easy On hold Temporary "on hold" status for maintainence OSCG26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement @st.cache_data for DB Read Operations

3 participants