Skip to content

fix(history-import): import Emby favorites - #378

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
d3v1l1989:fix/emby-favorites-import
Jul 16, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
d3v1l1989:fix/emby-favorites-import

Conversation

@d3v1l1989

@d3v1l1989 d3v1l1989 commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • fetch historical Emby movie and series favorites during history imports
  • add favorites without creating empty watch-progress rows
  • prefer Emby TMDB identity for favorite series while retaining TVDB/IMDb fallback
  • expose the number of newly imported favorites in user and admin run summaries

Why

Emby history import previously fetched only played and resumable items, so existing favorites were silently omitted.

Testing

  • go test ./...
  • database-backed history-import tests against temporary PostgreSQL tables
  • golangci-lint run
  • pnpm run lint
  • pnpm run format:check
  • pnpm test --run
  • pnpm run build
  • Goose migration validation
  • make verify-local-paths

Migration

Adds the additive, non-null history_import_runs.favorites_imported counter with a default of zero.

AI use

Codex assisted with implementation, test design, and review. Every changed line was reviewed and the full verification suite above was run.

Summary by CodeRabbit

  • New Features
    • History imports now include Emby movie and series favorites.
    • Import summaries now report how many favorites were imported.
    • Series matching can prioritize TMDb identifiers when appropriate (improves favorite matching accuracy).
  • UI
    • Added Favorites metrics to recent import details and history import run summaries.
  • Bug Fixes
    • Favorite-only items no longer create progress or watch-history entries.
    • Favorite fetching failures no longer stop the import; the import continues and reports a warning.

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Emby history imports now fetch and merge movie and series favorites, match series with optional TMDb preference, persist favorite-only records without progress or history, track imported favorite counts, and display those counts in the web UI.

Changes

Emby favorites import

Layer / File(s) Summary
Favorite fetching and matching
internal/historyimport/emby_client.go, internal/historyimport/emby_provider.go, internal/historyimport/matcher.go, internal/historyimport/types.go, internal/historyimport/*_test.go
Favorite movie and series records are fetched, merged with existing records, marked with favorite metadata, and matched with optional TMDb preference for series.
Favorite execution and counters
internal/historyimport/service.go, internal/historyimport/emby_favorites_test.go, internal/historyimport/plex_watchlist_test.go
Missing favorites are inserted, favorite-only records bypass progress and history processing, and favorite import counters and completion behavior are updated.
Atomic favorite insertion contract
internal/userstore/store.go, internal/userdb/*, internal/userstore/pgstore/*, internal/notifications/interest_hooks.go, internal/watchsync/lists.go, internal/*_test.go
AddFavoriteAt reports whether an insertion occurred, with SQLite, PostgreSQL, notification, sync, and conformance code updated to use the result.
Run persistence and schema
migrations/sql/*, internal/historyimport/repo.go, internal/historyimport/repo_admin.go, internal/historyimport/types.go
The favorites_imported column is migrated, stored, scanned, returned, and included in user and admin run queries.
Run metrics display
web/src/api/types.ts, web/src/pages/AdminHistoryImport.tsx, web/src/pages/settings/HistoryImportSettings.tsx
History import run details and summaries display the favorites imported count.

Estimated code review effort: 3 (Moderate) | ~30 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EmbyProvider
  participant EmbyClient
  participant Matcher
  participant Service
  participant UserStore
  participant WebUI
  EmbyProvider->>EmbyClient: Fetch favorite movies and series
  EmbyClient-->>EmbyProvider: Favorite items
  EmbyProvider->>Matcher: Match merged favorite records
  Matcher-->>Service: Matched records
  Service->>UserStore: AddFavoriteAt
  UserStore-->>Service: Inserted flag
  Service-->>WebUI: Run metrics including favorites_imported
Loading

Suggested labels: v1

Suggested reviewers: quick104

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the core change: importing Emby favorites in history import.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 68fcf89bf8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/historyimport/emby_provider.go Resolved

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/historyimport/emby_provider_test.go`:
- Around line 66-73: Add PreferTMDB assertions to the merged movie and series
checks in the favorites test, requiring the flag to be true for both records
while preserving the existing favorite and kind validations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7ecaedd1-3193-4465-83a1-ffcbc9bf2f43

📥 Commits

Reviewing files that changed from the base of the PR and between 28c6ddc and 68fcf89.

📒 Files selected for processing (15)
  • internal/historyimport/emby_client.go
  • internal/historyimport/emby_favorites_test.go
  • internal/historyimport/emby_provider.go
  • internal/historyimport/emby_provider_test.go
  • internal/historyimport/matcher.go
  • internal/historyimport/matcher_test.go
  • internal/historyimport/plex_watchlist_test.go
  • internal/historyimport/repo.go
  • internal/historyimport/repo_admin.go
  • internal/historyimport/service.go
  • internal/historyimport/types.go
  • migrations/sql/20260711114310_history_import_favorites_imported.sql
  • web/src/api/types.ts
  • web/src/pages/AdminHistoryImport.tsx
  • web/src/pages/settings/HistoryImportSettings.tsx

@d3v1l1989

Copy link
Copy Markdown
Contributor Author

Addressed both automated review findings in 22ea0c29:

  • Emby IsFavorite failures are now downgraded to warnings, so already-fetched played/resumable history still imports.
  • Added explicit PreferTMDB merge assertions for both movie and series favorites.
  • Added regression coverage for a 500 response from the favorites endpoint.

Verification: go test ./internal/historyimport -count=1 and golangci-lint run both pass. Both inline review threads have been replied to and resolved.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
internal/notifications/interest_hooks.go (1)

110-116: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

This change elegantly avoids redundant interest queue mutations when a favorite already exists. However, AddFavorite (defined just above) still unconditionally queues mutations because it doesn't know if an insertion occurred.

Consider delegating AddFavorite to AddFavoriteAt so it shares this deduplication logic:

func (s *interestTrackingStore) AddFavorite(ctx context.Context, profileID, mediaItemID string) error {
	_, err := s.AddFavoriteAt(ctx, profileID, mediaItemID, time.Now().UTC())
	return err
}
internal/userstore/pgstore/favorites.go (1)

18-32: 🧹 Nitpick | 🔵 Trivial

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/notifications/interest_hooks.go`:
- Around line 110-116: Update interestTrackingStore.AddFavorite to delegate to
AddFavoriteAt using the current UTC time, return only the delegated error, and
remove its separate mutation-queue logic so favorite additions share the
inserted-only behavior implemented by AddFavoriteAt.

In `@internal/userstore/pgstore/favorites.go`:
- Around line 18-32: Update interestTrackingStore.AddFavorite to delegate to
AddFavoriteAt using the current timestamp, then return its error. This ensures
QueueItemMutation is triggered only when AddFavoriteAt reports that a new
favorite was inserted, matching the existing AddFavoriteAt behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3c3eaccd-a98b-48e8-852a-56bbe2fa4b71

📥 Commits

Reviewing files that changed from the base of the PR and between 68fcf89 and 009b8ca.

📒 Files selected for processing (13)
  • internal/access/resolver_test.go
  • internal/historyimport/emby_favorites_test.go
  • internal/historyimport/emby_provider.go
  • internal/historyimport/emby_provider_test.go
  • internal/historyimport/service.go
  • internal/jellycompat/content_direct_test.go
  • internal/notifications/interest_hooks.go
  • internal/userdb/conformance_test.go
  • internal/userdb/favorites.go
  • internal/userdb/sqlitestore.go
  • internal/userstore/pgstore/favorites.go
  • internal/userstore/store.go
  • internal/watchsync/lists.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/historyimport/service.go

@Quick104
Quick104 merged commit 255b1be into Silo-Server:main Jul 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1.0 Silo v1 scope - auto-adds to the Silo v1 project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants