Commit Graph

36 Commits

Author SHA1 Message Date
Matthieu B
6cb00478da Merge pull request #1203 from wizarrrr/fix/1121-watch-time-calculation
fix: use playback position instead of file duration for watch time
2026-03-29 16:25:47 +02:00
Matthieu B
73c29458fe fix: resolve all test failures, linting errors, and type errors
- Fix 55 test failures caused by missing request contexts and incorrect
  session_transaction() usage across 8 test files
- Fix ruff import sorting errors and unused imports
- Fix 122 type errors: rename method override parameters to match base
  classes, add None guards for fetchone()/datetime, widen dict type
  annotations, add type: ignore for SQLAlchemy stub limitations
- Add [tool.ty.rules] config to suppress unsupported-base warnings
- Fix _ variable shadowing gettext in wizard routes
- Add noqa: ARG002 for unused method arguments required by base class
2026-03-29 16:20:23 +02:00
Matthieu B
65ed356d62 fix: use playback position instead of file duration for watch time (#1121)
Jellyfin and Emby collectors were recording RunTimeTicks (total file
runtime) as the session duration, causing severe overestimation when
users stopped partway through long titles.

- JellyfinCollector._emit_session_event: on session_end, use position_ms
  (last known playback position) as duration_ms; fall back to
  raw_duration_ms only when position_ms is unavailable or zero.
- EmbyCollector._emit_session_event: identical fix (shared API shape).
- JellyfinHistoricalImporter._process_item: for partially-watched items
  (UserData.Played == false) use PlaybackPositionTicks; keep RunTimeTicks
  only for fully-played items where position has already been reset.
- historical_duration_source metadata field now accurately reflects
  which source was used (runtime_ticks, playback_position_ticks, or
  runtime_ticks_fallback).

Plex was already correct via elapsed-time tracking in SessionManager.
2026-03-29 16:15:56 +02:00
Tim Gilmore
3612b09ecc changed watch to stream 2026-02-04 20:33:02 -08:00
Matthieu B
a8263ee0ac fix: highlight active session user names in activity table 2025-11-06 13:04:24 +01:00
Matthieu B
da8d008398 feat: revamp activity measurement and display 2025-11-04 18:55:11 +01:00
Matthieu B
c915e3c530 refactor: remove PlexCollector and update monitoring to use PollingCollector for Plex 2025-11-04 18:03:56 +01:00
Matthieu B
2283c4de68 fix: prevent startup race condition during migrations
This fixes a critical issue where Gunicorn workers would fail to start
after upgrading to v2025.11.0, causing containers to show as unhealthy
with only the uv wrapper process running and no actual workers.

Root Cause:
-----------
In v2025.11.0, library scanning and session recovery were added to the
create_app() function, which runs during EVERY app creation including:
1. During 'flask db upgrade' (migrations)
2. During Gunicorn master when_ready() hook
3. During each Gunicorn worker spawn

The migration 20251103_properly_fix_foreign_keys recreates 4 database
tables with CASCADE foreign keys using raw SQL. This holds exclusive
database locks during table recreation.

When library scanning and session recovery try to query these tables
during migration, they hit database locks, creating a race condition
that causes workers to timeout and crash during startup.

Fix:
----
- Skip library scanning during migrations (FLASK_SKIP_SCHEDULER=true)
- Skip activity monitoring/session recovery during migrations
- Make Gunicorn log level configurable (GUNICORN_LOG_LEVEL env var)
- Add worker lifecycle hooks for better crash debugging
- Increase healthcheck start period from 10s to 60s
- Increase Gunicorn worker timeout from 30s to 120s

Testing:
--------
- Verified app starts successfully with FLASK_SKIP_SCHEDULER=true
- Verified library scanning runs normally without the flag
- Confirmed 0.38s startup during migrations vs 1.61s normal startup

Closes #976
2025-11-03 20:41:52 +01:00
Matthieu B
d8bdc832c9 test: add assertions to ensure WizardStep retrieval after edits 2025-11-03 17:45:10 +01:00
Matthieu B
ff92ad1c54 feat: enhance Plex session management with Tautulli-inspired polling and immediate enrichment 2025-11-03 15:33:26 +01:00
Douw Jacobs
4e9064d130 fix: aligned media-type-filter Audiobooks value with mediaType tag coming from ABS 2025-10-30 16:44:14 +02:00
Douw Jacobs
dd0c8346df fix: keep filter paramters when switching pages 2025-10-30 15:59:12 +02:00
Matthieu B
3d97dda0fb fix: error in nwo playing cards 2025-10-23 20:10:04 +02:00
Matthieu B
6a3632ec66 refactor: update type hints for better clarity and consistency across multiple files 2025-10-23 19:49:58 +02:00
Matthieu B
9b5aa0972a refactor: remove slop from media and new linting rules 2025-10-23 18:33:50 +02:00
Matthieu B
1618ce7791 feat: enhance session management with Tautulli-inspired enrichment and validation for statistics 2025-10-22 12:49:57 +02:00
Matthieu B
07166a1a80 refactor: update Emby collector to use Sessions API polling instead of WebSocket
fix: correct key for transcoding info in admin routes
feat: enhance Jellyfin client to extract additional session and media details
fix: update template to reflect changes in transcoding info structure
chore: update submodule reference for plus
2025-10-21 11:48:07 +02:00
Matthieu B
55bdcd10ba fix: Enhance session data validation and logging for incomplete data handling 2025-10-20 12:12:35 +02:00
Matthieu B
e184b0a676 fix: Add session re-fetching capability in PlexCollector for incomplete data handling 2025-10-20 11:42:23 +02:00
Matthieu B
9ea2fa10b2 fix: Improve Plex server connection logging to include account username 2025-10-19 17:02:56 +02:00
Matthieu B
6ab5e024db Revert "Merge pull request #925 from wizarrrr/chore/python-3.14-upgrade"
This reverts commit 35dde7c19a, reversing
changes made to c8cf9905ba.
2025-10-19 14:05:59 +02:00
Matthieu B
35dde7c19a Merge pull request #925 from wizarrrr/chore/python-3.14-upgrade
chore: Update to python 3.14
2025-10-19 13:47:39 +02:00
Matthieu B
294194eca7 Refactor code structure for improved readability and maintainability 2025-10-18 17:51:32 +02:00
Matthieu B
36227c762b refactor: Update type hints for user details methods and other functions for improved clarity 2025-10-18 17:42:26 +02:00
Matthieu B
bde092a9d3 feat: Set Flask environment to production and adjust app configuration loading 2025-10-18 17:34:25 +02:00
Matthieu B
3965444133 refactor: Rename environment variable for enabling Plus features to improve clarity 2025-10-18 16:15:48 +02:00
Matthieu B
45053f041f Refactor historical data import service
- Moved utility functions for datetime parsing, tick conversion, and session building from `historical_data.py` to a new module `utils.py`.
- Deleted the `historical_data.py` file as its functionality is now encapsulated in the new utility module.
- Updated the `build_activity_session` function to utilize the new utility functions for improved readability and maintainability.
2025-10-18 15:37:48 +02:00
Matthieu B
456f209204 Potential fix for code scanning alert no. 69: Information exposure through an exception
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2025-10-18 13:00:28 +02:00
Matthieu B
c6db372e70 Update app/activity/monitoring/collectors/__init__.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-18 12:59:21 +02:00
Matthieu B
1437895e0b fix: Update server name references in Emby collector and activity templates
feat: Implement numbered pagination component in activity table
2025-10-18 12:41:32 +02:00
Matthieu B
76f9480ada feat: Add support for AudiobookShelf in historical data import functionality 2025-10-17 15:48:10 +02:00
Matthieu B
01b67cda52 Enhance Activity Settings and Historical Data Import Functionality
- Redesigned the Activity Settings page for improved user experience, including better organization of sections and updated alert messages.
- Added functionality to import historical data from Jellyfin and Emby servers, allowing users to specify the number of days back and a result limit for imports.
- Updated the HistoricalDataService to support importing history from Jellyfin and Emby, including detailed logging and error handling.
- Improved the UI for historical data import, including form validation and user feedback during the import process.
- Cleaned up completed historical import jobs from the database to prevent indefinite persistence.
2025-10-17 15:26:43 +02:00
Matthieu B
77a1112d62 feat: Add historical import job functionality
- Introduced the HistoricalImportJob model to track historical data import jobs.
- Implemented asynchronous job processing for importing historical activity data from media servers.
- Enhanced the activity settings page to allow users to specify the number of days back for historical imports.
- Added a new route to display recent historical import jobs.
- Updated the import_historical_activity function to create and manage import jobs.
- Improved UI components for displaying success and error messages related to historical imports.
- Added migration script to create the historical_import_job table in the database.
2025-10-17 13:14:37 +02:00
Matthieu B
f886db9124 feat(audiobookshelf): Track session start times and calculate elapsed duration for events 2025-10-17 12:04:12 +02:00
Matthieu B
8361144972 feat(activity): Enhance activity monitoring with historical data import and management features 2025-10-17 11:00:33 +02:00
Matthieu B
0ac98355dd feat(activity): Implement activity ingestion, identity resolution, and maintenance services
- Added `identity_resolution.py` for resolving Wizarr users and identities.
- Created `ingestion.py` to handle recording and updating activity events.
- Introduced `maintenance.py` for cleanup and session management tasks.
- Developed `queries.py` for read-oriented operations on activity sessions.
- Implemented background tasks in `activity.py` for scheduled maintenance.
- Added tests for activity services and blueprint to ensure functionality.
2025-10-16 15:18:31 +02:00