Skip to content

Conversation

adamantike
Copy link
Contributor

@adamantike adamantike commented Aug 10, 2025

Description
When retrieving the related screenshot for a Save or State, we were retrieving a very heavy representation of the associated Rom object, only to iterate through its screenshots to find the one we needed.

This change modifies the Save and State models to directly query the Screenshot model, which is much faster and more efficient. The DBScreenshotsHandler has been updated to include a new filter method that will simplify building queries using SQLAlchemy, something we can extend to other handlers in the future.

Fixes #1925.

Checklist

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

When retrieving the related screenshot for a `Save` or `State`, we were
retrieving a very heavy representation of the associated `Rom` object,
only to iterate through its screenshots to find the one we needed.

This change modifies the `Save` and `State` models to directly query the
`Screenshot` model, which is much faster and more efficient. The
`DBScreenshotsHandler` has been updated to include a new `filter` method
that will simplify building queries using SQLAlchemy, something we can
extend to other handlers in the future.

Fixes #1925.
@adamantike adamantike requested review from gantoine and zurdi15 August 10, 2025 18:34
Copy link

trunk-io bot commented Aug 10, 2025

Running Code Quality on PRs by uploading data to Trunk will soon be removed. You can still run checks on your PRs using trunk-action - see the migration guide for more information.

Copy link

Test Results

548 tests  ±0   547 ✅ ±0   56s ⏱️ -2s
  1 suites ±0     1 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 00d7815. ± Comparison against base commit 40e824d.

Copy link

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
8754 6175 71% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
backend/endpoints/saves.py 30% 🟢
backend/endpoints/screenshots.py 34% 🟢
backend/endpoints/states.py 30% 🟢
backend/handler/database/screenshots_handler.py 83% 🟢
backend/models/assets.py 96% 🟢
TOTAL 55% 🟢

updated for commit: 00d7815 by action🐍

@adamantike adamantike merged commit edbff6b into master Aug 10, 2025
9 checks passed
@adamantike adamantike deleted the fix/performance-asset-screenshot branch August 10, 2025 19:05
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.

[Bug] Improve load times of games with many save states
2 participants