From f9eb3e137dd74942ad850ded2774ea29255b1f0c Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 8 Oct 2021 22:55:54 -0400 Subject: [PATCH] Remove redundant updates on finishing a media item --- .../API/Kitsu/Queries/GetUserHistory.graphql | 6 ++++++ .../API/Kitsu/Transformer/HistoryTransformer.php | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql b/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql index 4dd35bc2..61c795dc 100644 --- a/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql +++ b/src/AnimeClient/API/Kitsu/Queries/GetUserHistory.graphql @@ -30,6 +30,12 @@ query ($slug: String!) { canonical localized } + ...on Anime { + episodeCount + } + ...on Manga { + chapterCount + } } updatedAt } diff --git a/src/AnimeClient/API/Kitsu/Transformer/HistoryTransformer.php b/src/AnimeClient/API/Kitsu/Transformer/HistoryTransformer.php index 1a37f9f0..5c522dcf 100644 --- a/src/AnimeClient/API/Kitsu/Transformer/HistoryTransformer.php +++ b/src/AnimeClient/API/Kitsu/Transformer/HistoryTransformer.php @@ -65,6 +65,7 @@ abstract class HistoryTransformer { foreach ($base as $entry) { + // Filter out other media types if (strtolower($entry['media']['__typename']) !== $this->type) { continue; @@ -195,6 +196,19 @@ abstract class HistoryTransformer { return NULL; } + // Hide the last episode update (Anime) + foreach (['episodeCount', 'chapterCount'] as $count) + { + if ( ! empty($entry['media'][$count])) + { + $update = $entry['changedData']['progress'][1] ?? 0; + if ($update === $entry['media'][$count]) + { + return NULL; + } + } + } + $action = ($this->isReconsuming($entry)) ? "{$this->reconsumeAction} {$item}" : "{$this->progressAction} {$item}";