Skip to content

Server optimizations#972

Merged
martastain merged 15 commits into
developfrom
redis-optimizations
Jun 12, 2026
Merged

Server optimizations#972
martastain merged 15 commits into
developfrom
redis-optimizations

Conversation

@martastain

@martastain martastain commented Jun 11, 2026

Copy link
Copy Markdown
Member

This pull request introduces several improvements and refactors related to thumbnail generation and session management. The main focus is on centralizing the thumbnail size configuration, improving concurrency and error handling in video thumbnail creation, and cleaning up session expiration logic. Below are the most important changes grouped by theme:

  • Introduced a single configuration option thumbnail_size in ayonconfig, replacing hardcoded max width/height values across the codebase for thumbnail and preview generation. All relevant logic now uses ayonconfig.thumbnail_size for consistency.
  • Updated create_video_thumbnail to accept a thumbnail flag and use the centralized thumbnail size. Also improved ffmpeg command construction and logging for better traceability and debugging.
  • Added a concurrency limit to video thumbnail generation using an asyncio semaphore, preventing overload from simultaneous requests.
  • Improved error handling for thumbnail generation, including proper cancellation and logging of ffmpeg errors.

Caching and Performance

  • Standardized thumbnail cache headers for long-term caching and removed random cache max-age logic, ensuring better CDN/browser caching behavior.
  • Reduced the retry count for file preview generation from 5 to 3, improving responsiveness in failure scenarios.
  • Integrated RequestCoalescer for file preview requests to deduplicate concurrent requests for the same resource, reducing redundant processing.

Session Management Refactor

  • Refactored session expiration logic by moving TTL and expiration checks into SessionModel properties (ttl, is_expired), simplifying code and improving maintainability.
  • Updated session check logic to use the new properties and improved Redis session update formatting.

Other Improvements

  • Improved Redis key handling by making decoding/removal of prefixes more robust in the keys method.
  • Reduced the thumbnail Redis cache TTL from 7200 to 600 seconds for more frequent updates.

These changes collectively improve configurability, maintainability, and reliability of thumbnail and session handling in the application.

@BigRoy BigRoy added the type: enhancement Improvement of existing functionality or minor addition label Jun 11, 2026
@martastain martastain marked this pull request as ready for review June 12, 2026 07:39
@martastain martastain requested a review from Copilot June 12, 2026 07:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR focuses on reducing Redis cache pressure and tightening concurrency around preview/thumbnail generation, while making thumbnail sizing configurable via server config.

Changes:

  • Reduced Redis-cached thumbnail TTL from 2 hours to 10 minutes.
  • Introduced ayonconfig.thumbnail_size and routed thumbnail resizing through config instead of hardcoded constants.
  • Added a global semaphore around ffmpeg thumbnail extraction and coalesced concurrent preview requests.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cli/optimize_thumbnails/optimize_thumbnails.py Uses configured thumbnail size when optimizing thumbnails.
ayon_server/lib/redis.py Makes Redis.keys() resilient to both bytes and str key types.
ayon_server/helpers/thumbnails/store_thumbnail.py Uses configured thumbnail size when storing thumbnails.
ayon_server/helpers/thumbnails/process_thumbnail.py Removes hardcoded thumbnail size constants (now config-driven elsewhere).
ayon_server/helpers/thumbnails/common.py Reduces Redis TTL for thumbnail retrieval caching and adjusts response headers order.
ayon_server/helpers/preview.py Adds semaphore for ffmpeg work and request coalescing for file previews.
ayon_server/config/ayonconfig.py Adds thumbnail_size configuration option.
ayon_server/auth/session.py Refactors session TTL/expiry logic into SessionModel properties.
api/files/files.py Updates still-frame extraction call site for new create_video_thumbnail signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ayon_server/helpers/thumbnails/common.py
@martastain martastain changed the title Redis optimizations Server optimizations Jun 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.

Comment thread maintenance/tasks/add_missing_project_indexes.py Outdated
Comment thread ayon_server/helpers/thumbnails/thumbnail_info_resolvers.py
Comment thread ayon_server/helpers/thumbnails/thumbnail_info_resolvers.py
Comment thread ayon_server/helpers/preview.py Outdated
Comment thread ayon_server/config/ayonconfig.py
martastain and others added 3 commits June 12, 2026 14:29
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.

Comment thread ayon_server/helpers/thumbnails/thumbnail_info_resolvers.py
Comment thread ayon_server/helpers/thumbnails/thumbnail_info_resolvers.py Outdated
Comment thread ayon_server/helpers/thumbnails/common.py
Comment thread ayon_server/config/ayonconfig.py
Comment thread ayon_server/helpers/preview.py Outdated
Comment thread ayon_server/helpers/preview.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Comment thread ayon_server/helpers/preview.py
Comment thread ayon_server/helpers/preview.py
Comment thread schemas/schema.project.sql
Comment thread maintenance/tasks/add_missing_project_indexes.py
@martastain martastain merged commit dcc8f92 into develop Jun 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement Improvement of existing functionality or minor addition

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants