Skip to content

Conversation

@Yundi339
Copy link
Contributor

@Yundi339 Yundi339 commented Feb 8, 2026

Description

I think the log interface returns the full amount every time, which is an unreasonable mechanism.
Of course, I did consider using SSE, but it's not a good fit here. It would just introduce unnecessary complexity and over-engineering. So I tried to do these things.

Logs API improvements:

  • Incremental fetch: client sends X-Log-Offset in request header, server returns only new bytes and X-Log-Size in response. Avoids re-sending the full file every 5s.
  • HTTP 304 when offset already equals file size (no body).
  • Backend cache: re-read log file only when size or mtime changes; use std::atomic<std::shared_ptr> for thread-safe access without locks.
  • Pause polling when tab is hidden (Page Visibility API); resume and refresh when visible.
  • Handle non-2xx and 304 so failed responses don’t overwrite existing log content.
  • Sunshine uses try_incremental_log_read to avoid getting the full logs every time.

============
I know that modifying code related to file operations is an act that is prone to dangerous problems.
Therefore, I suggest that this PR should not be in a hurry to integrate, I will use it locally for a long time to see the stability.

BTW, I added log files to sunshinesvc.cpp on PC, so I could know when Sunshine.exe had a safe and unsafe restart.

Screenshot

image

Issues Fixed or Closed

Roadmap Issues

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

@Yundi339 Yundi339 changed the title feat: optimize logs API: incremental fetch, 304, visibility pause, and safe caching feat: make the api/logs more elegant Feb 10, 2026
@Yundi339
Copy link
Contributor Author

To prevent indefinite memory growth, a setting should be added in the future to limit the buffer size (e.g., 1MB, 10MB, 50MB). This would not affect the local log files. For example, if set to 10MB, the system should only read the trailing 10MB of the file.

@Yundi339 Yundi339 changed the title feat: make the api/logs more elegant feat(confighttp): make the api/logs more elegant Feb 10, 2026
@ReenigneArcher
Copy link
Member

Thanks for the PRs! For this one specifically, I think I want to get #4645 finished and merged first.

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