Skip to content

refactor: remove global reverseDirection + code quality fixes#59

Merged
bigspawn merged 8 commits intomainfrom
fix/code-quality
Mar 1, 2026
Merged

refactor: remove global reverseDirection + code quality fixes#59
bigspawn merged 8 commits intomainfrom
fix/code-quality

Conversation

@bigspawn
Copy link
Copy Markdown
Owner

@bigspawn bigspawn commented Mar 1, 2026

Summary

Code quality fixes and refactoring on top of the favorites feature branch.
Base branch: feature/favorites-clean (merge that first, then this).

Changes

🔴 Critical

  • Remove global reverseDirection — replaced with isReverse bool field on Anime/Manga structs; Reverse bool on Updater, ManualMappingStrategy, AniListAnimeService, AniListMangaService. GetTargetID()/GetSourceID() are now direction-aware per-instance.

🟠 High

  • Delete dead id_helpers.goGetTargetIDWithDirection/GetSourceIDWithDirection had zero callers after the refactoring above
  • Fix logging.goRoundTrip now uses l.verbose struct field instead of the *verbose global
  • DPrintfLogDebug(ctx, ...) — 13 no-op debug calls restored with proper context propagation; ctx threaded through normalizeScoreForMAL, denormalizeScoreForAniList, titleMatchingLevels, exactMatch, normalizedMatch, fuzzyMatch, levenshteinMatch; SameTitleWithTarget/SameTypeWithTarget interface updated to accept ctx

🟡 Medium

  • Remove setSyncFlagsFromCmd — one-liner alias for getSyncFlagsFromCmd, callers updated
  • Remove unreachable anilistID > 0 branch in lookupReverse (MAL sources always have IDAnilist=0)
  • NewSyncReport() now initializes all 4 slices (UnmappedItems, FavoritesMismatches were nil)
  • printGlobalFavorites — remove dead if reverse branch (mismatches only populated in forward direction)

🟢 Low

  • Delete Manga.GetUpdateMyAnimeListStatusOption() — nil stub with zero callers
  • Remove triple fetch indirectionperformSync calls fetchFromAnilistToMAL/fetchFromMALToAnilist directly; deleted fetchData, fetchNormalSyncData, fetchReverseSyncData
  • Refresh() resets ResolvedMappings — was missing from watch-mode state reset loop

Tests

  • fixes_test.go — covers all fixes above
  • Updated t.Context() propagation in all affected test files

@bigspawn bigspawn changed the base branch from feature/favorites-clean to main March 1, 2026 11:00
bigspawn added 8 commits March 1, 2026 12:15
…in objects

Replace the package-level *reverseDirection pointer with an isReverse bool
field on Anime and Manga structs. Direction is now carried by each value
rather than read from a global at call time.

Key changes:
- Anime.isReverse / Manga.isReverse: replaces *reverseDirection in
  GetTargetID() and GetSourceID()
- All MAL constructors (newAnimeFromMalAnime, newMangasFromMalUserMangas,
  etc.) take a reverse bool param and propagate isReverse
- AniList constructors (newAnimesFromMediaListGroups, newAnimeFromVerniyMedia,
  etc.) take a reverse bool param so AniList targets in reverse sync also
  carry isReverse=true for correct GetTargetID() behaviour
- ManualMappingStrategy{Reverse bool}: lookupByIDs uses s.Reverse
- Updater{Reverse bool}: generateUpdateDetail and trackUnmapped use u.Reverse
- AniListAnimeService / AniListMangaService carry Reverse bool, propagate to
  returned Anime/Manga entries
- NewApp(ctx, config, reverse bool): direction passed explicitly from CLI
- PrintGlobalSummary takes reverse bool instead of reading global
- Run() resets the four fetchedXxx cache fields at the start of each call
  (important for watch mode — prevents stale data across runs)
- reverseDirection global removed from main.go and cli.go
@bigspawn bigspawn merged commit bde2af3 into main Mar 1, 2026
3 checks passed
@bigspawn bigspawn deleted the fix/code-quality branch March 1, 2026 11:46
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.

1 participant