Skip to content

Commit

Permalink
v5.10.x Formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
terrelsa13 committed Jan 12, 2025
1 parent a9425b4 commit d7c7160
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
16 changes: 14 additions & 2 deletions mumc_modules/mumc_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ def wipeCache(self):
self.oldest_cached_data_entry_number=None
self.total_cumulative_cached_data_entry_number=None


def checkURLInCache(self,url):
if (url in self.cached_entry_urls):
return True
else:
return False


def getIndexFromURL(self,url):
if (self.checkURLInCache(url)):
return self.cached_entry_urls.index(url)
else:
return None


def getCachedDataFromURL(self,url):
try:
if (not ((index:=self.getIndexFromURL(url)) == None)):
Expand All @@ -76,6 +79,7 @@ def getCachedDataFromURL(self,url):
except:
raise ValueError('Error returning cached data for url: ' + url + ' at index: ' + index + '\n')


#Recursively find size of data objects
#Credit to https://github.com/bosswissam/pysize/blob/master/pysize.py
def getDataSize(self,obj,seen=None):
Expand Down Expand Up @@ -108,6 +112,7 @@ def getDataSize(self,obj,seen=None):

return size


def removeCachedEntry(self,url):
try:
index=self.getIndexFromURL(url)
Expand All @@ -128,6 +133,10 @@ def removeCachedEntry(self,url):
return False


def getHighestAttributeValueCacheEntryIndex(self,cached_data_list):
return cached_data_list.index(max(cached_data_list))


def getLowestAttributeValueCacheEntryIndex(self,cached_data_list):
return cached_data_list.index(min(cached_data_list))

Expand All @@ -148,10 +157,10 @@ def addEntryToCache(self,url,data):
temp_cached_entry_times=self.cached_entry_times.copy()
while estimatedEntryDataSize > (self.api_query_cache_size - self.total_cached_data_size):
if (len(self.cached_entry_sizes) > 0):
#LFU get least accessed cache entry
#LFU; get least accessed cache entry
least_accessed_entry_index=self.getLowestAttributeValueCacheEntryIndex(temp_cached_entry_hits)

#Verify entry is outside of the safety window
#LRU; verify entry is outside of the safety window
if (temp_cached_entry_times[least_accessed_entry_index] < safety_time_window):
self.removeCachedEntry(self.cached_entry_urls[self.getIndexFromURL(temp_cached_entry_urls[least_accessed_entry_index])])
temp_cached_entry_hits=self.cached_entry_hits.copy()
Expand All @@ -163,12 +172,15 @@ def addEntryToCache(self,url,data):
temp_cached_entry_times.pop(least_accessed_entry_index)

if (len(temp_cached_entry_hits) == 0):
#First In First Out
if (self.api_query_cache_fallback_behavior == 'FIFO'):
#FIFO Remove oldest cached entry
self.removeCachedEntry(self.cached_entry_urls[0])
#Least Frequently Used
elif (self.api_query_cache_fallback_behavior == 'LFU'):
#LFU Remove oldest and least accessed cache entry
self.removeCachedEntry(self.cached_entry_urls[self.getLowestAttributeValueCacheEntryIndex(self.cached_entry_hits)])
#Last Recently Used
else: #(self.api_query_cache_fallback_behavior == 'LRU'):
#LRU Remove cache entry with oldest access time
self.removeCachedEntry(self.cached_entry_urls[self.getLowestAttributeValueCacheEntryIndex(self.cached_entry_times)])
Expand Down
2 changes: 1 addition & 1 deletion mumc_modules/mumc_minimum_episodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def determine_playedUnplayedToRemain(self):


#loop thru each item in the list of items that may be deleted
def buildSeason_byEpisodeGrid(self):
def buildSeason_x_EpisodeGrid(self):
for deleteItem in self.deleteItems:
#verify media item is an episode
if (deleteItem['Type'] == 'Episode'):
Expand Down
1 change: 0 additions & 1 deletion mumc_modules/mumc_paths_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def doesDirectoryExist(PathName):
return pathExists



def getFileExtension(path_or_filename):
if (doesFileExist(path_or_filename)):
return Path(path_or_filename).suffix
Expand Down
2 changes: 1 addition & 1 deletion mumc_modules/mumc_post_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def postProcessing(the_dict,media_dict):
postproc_dict['minEpisodesToKeep']=minEpisodesToKeep_data_handler(postproc_dict,the_dict)
postproc_dict['minEpisodesToKeep'].trackEpisodes_byUserId()
postproc_dict['minEpisodesToKeep'].determine_playedUnplayedToRemain()
postproc_dict['minEpisodesToKeep'].buildSeason_byEpisodeGrid()
postproc_dict['minEpisodesToKeep'].buildSeason_x_EpisodeGrid()
postproc_dict['minEpisodesToKeep'].determine_minimumEpisodeBehavioralType()
postproc_dict['minEpisodesToKeep'].calc_userSpecificBehavioralTypeData()
postproc_dict['minEpisodesToKeep'].find_playedEpisodesToKeep()
Expand Down
4 changes: 2 additions & 2 deletions mumc_modules/mumc_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def requestURL(url, debugState, requestDebugMessage, retries, the_dict):
#number of times after the intial API request to retry if an exception occurs
retryAttempts = int(retries)

#check if this url is cached and is method is GET; return the cached data if true
if ((not ((data:=the_dict['cached_data'].getCachedDataFromURL(url.full_url)) == None)) and (url.method == 'GET')):
#check if the method is GET and this url is cached; return the cached data if true
if ((url.method == 'GET') and (not ((data:=the_dict['cached_data'].getCachedDataFromURL(url.full_url)) == None))):
#request is cached; do not send request to server
getdata = False
else:
Expand Down
2 changes: 1 addition & 1 deletion mumc_modules/mumc_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#Get the current script version
def get_script_version():
return '5.10.2-beta'
return '5.10.3-beta'


#Get the min config version
Expand Down

0 comments on commit d7c7160

Please sign in to comment.