Skip to content

Commit

Permalink
wip cache publisher list
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Nov 11, 2024
1 parent 90056ef commit 4fb6bd5
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion dashboard/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def wrapper(self, key):
return wrapper


PUBLISHER_LIST = None


class JSONDir(MutableMapping):
"""Produces an object, to be used to access JSON-formatted publisher data and return
this as an ordered dictionary (with nested dictionaries, if appropriate).
Expand Down Expand Up @@ -115,13 +118,18 @@ def get_publisher_name(self):
Note, this is a super hacky way to do this, prize available if a better way is found to do this!
"""

global PUBLISHER_LIST

if PUBLISHER_LIST is None:
PUBLISHER_LIST = JSONDir(filepaths.join_stats_path('current/aggregated-publisher')).keys()

# Get a list of the parts that are contained within this filepath
path = os.path.normpath(self.folder)
path_components = path.split(os.sep)

# Loop over this list and return the publisher name if it is found within the historic list of publishers
for x in path_components:
if x in JSONDir(filepaths.join_stats_path("current/aggregated-publisher")).keys():
if x in PUBLISHER_LIST:
return x

# If got to the end of the loop and nothing found, this folder does not relate to a single publisher
Expand Down

0 comments on commit 4fb6bd5

Please sign in to comment.