Repository: pymedusa/Medusa

Issue:
Main page not reflecting correct 'next episode date'
**Bug description with screenshots**
There seems to be an issue with the 'main page'. See this first row:
![afbeelding](https://user-images.githubusercontent.com/807403/121176204-3c59da00-c85c-11eb-8e81-ce0e7959337c.png)
Now of these NCIS Hawai has one unaired episode, without a date, no idea why it is named as one of the first. "Have I got news for you" has currently no episodes listed:
![afbeelding](https://user-images.githubusercontent.com/807403/121176389-74611d00-c85c-11eb-9e3e-55a4de177827.png)
which is correct, but why is it showing 'Continuing' and not (like for instance Inside No 9 - see below) a date. Really strange is "The Great Sewing Bee" which has two more episodes planned:
![afbeelding](https://user-images.githubusercontent.com/807403/121176745-dde12b80-c85c-11eb-85c7-a7c4683b2850.png)
yet is shown as Continuing. And previously named "Inside No. 9" is shown with an airdate of yesterday, where in fact there is an episode scheduled in the next week:
![afbeelding](https://user-images.githubusercontent.com/807403/121176888-09fcac80-c85d-11eb-89cc-a48b01116f01.png)

**Medusa:**
 - OS: Synology via Linuxserver Docker
 - Branch: master
 - Commit:  b34f1df336e52cf0a690acbc393440ac9f8b3581
 - Python version: 3.8.10 (default, May 6 2021, 06:30:44) [GCC 9.3.0]
 - Database version: 44.18

**Debug logs (at least 50 lines):**
Nothing relevant found in the logs. Tried to intercept the JSON from the api calls and that is in line with the main page.


Discussion:
It needs to have a future episode with date, for it to be able to show in stead of `continuing`
For the show `have i got news for you`. Ep 9 was already in the past
> It needs to have a future episode with date, for it to be able to show in stead of `continuing`

Yes, that's what I thought. But as you can see it is showing the Sewing Bee as 'continuing' when it has two future episodes. And Inside No.9 is shown with the date of an already aired episode when there is a future episode.

> For the show `have i got news for you`. Ep 9 was already in the past

I know, it was just to show the difference between some shows showing an already past airdate and others that don't

As I have seen before, these issues miraculously solve over time. A few hours after posting this, all of a sudden the main page showed the correct dates/show statuses. My assumption was/is that the main page is built using data retrieved from the database directly and to circumvent any browser caching I forced retrieval of data. That did not do the trick, but given that is is resolved magically I am starting to suspect some caching/delayed updating somewhere in the chain.


Yes there is some caching here. I believe up to max 24 hours. If we don't it has to recalculate the next ep every time you load the shows page
> Yes there is some caching here. I believe up to max 24 hours. If we don't it has to recalculate the next ep every time you load the shows page

Hmmm.... is that a specific process (viewable in the Server Status)? Or otherwise any hints so I can monitor and see if that brings something forward that can be of help to anyone?
There is an episodeupdate thread that runs every 15 minutes, that checks if next episode needs to be recalculated. So that checks if for a show the cached (24 hours) ep needs a refresh
Given the example it feels like something doesn't go as planned. I checked and the 'episode updater' is enabled, so that is (probably) not it. As said, currently everything is as it should be, but as soon as the same issue reappears I will try to trace the episode updater to find out if I can find out why things are as they are.
I'm having the same issue, with some screenshots here to highlight it. Hell's Kitchen is the show, with the last episode airing 2 days ago (14th). That episode has already been downloaded and the next episode is on the 21st and has a time associated with it. The main page is stuck saying the 14th is the next episode though.

Here is the show:
![medusaissue1](https://user-images.githubusercontent.com/20057445/122215786-a59fa580-ce79-11eb-85c9-889576d19fe5.jpg)

The outdated main screen:
![medusaissue2](https://user-images.githubusercontent.com/20057445/122215809-b05a3a80-ce79-11eb-8a92-45bf06c82783.jpg)

And the status screen showing all seems well:
![medusaissue3](https://user-images.githubusercontent.com/20057445/122215898-c667fb00-ce79-11eb-8199-146da19c76ae.jpg)

I'm having the same issue. The Next Ep column is not updating but the shows are still downloading anyway on the proper dates. There is no apparent error in the logs

![image](https://user-images.githubusercontent.com/3161577/124302826-abf77800-db2f-11eb-87a7-9d5ec0f0326d.png)

![image](https://user-images.githubusercontent.com/3161577/124303582-a0f11780-db30-11eb-9aad-3a2b397fe99e.png)


Medusa Info: 
Branch: master
Commit: 64df36d92a354a89a69ac519911129a516b0c318 
Version: 0.5.13 
Database: 44.18
Python Version: | 3.8.5 (default, May 27 2021, 13:30:53) [GCC 9.3.0]
SSL Version: | OpenSSL 1.1.1f 31 Mar 2020
OS: Ubuntu 20.04.2 LTS | Linux-5.4.0-74-generic-x86_64-with-glibc2.29
Locale: | en_US.UTF-8
Timezone: | EDT



Resolving patch:
diff --git a/medusa/tv/series.py b/medusa/tv/series.py
--- a/medusa/tv/series.py
+++ b/medusa/tv/series.py
@@ -606,7 +606,7 @@ def next_aired(self):
         return self._next_aired
 
     @property
-    @ttl_cache(43200.0)
+    @ttl_cache(21600.0)
     def prev_airdate(self):
         """Return last aired episode airdate."""
         return (
@@ -615,7 +615,7 @@ def prev_airdate(self):
         )
 
     @property
-    @ttl_cache(43200.0)
+    @ttl_cache(21600.0)
     def next_airdate(self):
         """Return next aired episode airdate."""
         return (
@@ -1835,11 +1835,12 @@ def next_episode(self):
             [self.indexer, self.series_id, today])
 
         if sql_results is None or len(sql_results) == 0:
-            log.debug(u'{id}: Could not find a next episode', {'id': self.series_id})
+            log.debug(u'{id}: ({name}) Could not find a next episode', {'name': self.name, 'id': self.series_id})
         else:
             log.debug(
-                u'{id}: Found episode {ep}', {
+                u'{id}: ({name}) Found episode {ep}', {
                     'id': self.series_id,
+                    'name': self.name,
                     'ep': episode_num(sql_results[0]['season'], sql_results[0]['episode']),
                 }
             )


Test patch: