Fix trailing whitespace and finalize performance improvements
Co-authored-by: Nathanwoodburn <62039630+Nathanwoodburn@users.noreply.github.com>
This commit is contained in:
@@ -18,17 +18,17 @@ def get_nc_config():
|
||||
"""
|
||||
Get NC_CONFIG with caching (1 hour TTL).
|
||||
Falls back to default config on error.
|
||||
|
||||
|
||||
Returns:
|
||||
dict: Configuration dictionary
|
||||
"""
|
||||
global _nc_config_cache
|
||||
current_time = datetime.datetime.now().timestamp()
|
||||
|
||||
|
||||
# Check if cache is valid
|
||||
if _nc_config_cache["data"] and (current_time - _nc_config_cache["timestamp"]) < _nc_config_ttl:
|
||||
return _nc_config_cache["data"]
|
||||
|
||||
|
||||
# Fetch new config
|
||||
try:
|
||||
config = requests.get(
|
||||
@@ -53,17 +53,17 @@ _git_data_ttl = 300 # 5 minutes cache
|
||||
def get_git_latest_activity():
|
||||
"""
|
||||
Get latest git activity with caching (5 minute TTL).
|
||||
|
||||
|
||||
Returns:
|
||||
dict: Git activity data or default values
|
||||
"""
|
||||
global _git_data_cache
|
||||
current_time = datetime.datetime.now().timestamp()
|
||||
|
||||
|
||||
# Check if cache is valid
|
||||
if _git_data_cache["data"] and (current_time - _git_data_cache["timestamp"]) < _git_data_ttl:
|
||||
return _git_data_cache["data"]
|
||||
|
||||
|
||||
# Fetch new data
|
||||
try:
|
||||
git = requests.get(
|
||||
@@ -78,11 +78,11 @@ def get_git_latest_activity():
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"Error fetching git data: {e}")
|
||||
|
||||
|
||||
# Return cached or default
|
||||
if _git_data_cache["data"]:
|
||||
return _git_data_cache["data"]
|
||||
|
||||
|
||||
return {
|
||||
"repo": {
|
||||
"html_url": "https://nathan.woodburn.au",
|
||||
@@ -100,20 +100,20 @@ _projects_ttl = 7200 # 2 hours cache
|
||||
def get_projects(limit=3):
|
||||
"""
|
||||
Get projects list with caching (2 hour TTL).
|
||||
|
||||
|
||||
Args:
|
||||
limit (int): Number of projects to return
|
||||
|
||||
|
||||
Returns:
|
||||
list: List of project dictionaries
|
||||
"""
|
||||
global _projects_cache
|
||||
current_time = datetime.datetime.now().timestamp()
|
||||
|
||||
|
||||
# Check if cache is valid
|
||||
if _projects_cache["data"] and (current_time - _projects_cache["timestamp"]) < _projects_ttl:
|
||||
return _projects_cache["data"][:limit]
|
||||
|
||||
|
||||
# Fetch new data
|
||||
try:
|
||||
projects = []
|
||||
@@ -122,7 +122,7 @@ def get_projects(limit=3):
|
||||
timeout=5
|
||||
)
|
||||
projects = projectsreq.json()
|
||||
|
||||
|
||||
# Check for pagination
|
||||
pageNum = 2
|
||||
while 'rel="next"' in projectsreq.headers.get("link", ""):
|
||||
@@ -135,16 +135,16 @@ def get_projects(limit=3):
|
||||
# Safety limit
|
||||
if pageNum > 10:
|
||||
break
|
||||
|
||||
|
||||
# Process projects
|
||||
for project in projects:
|
||||
if project.get("avatar_url") in ("https://git.woodburn.au/", ""):
|
||||
project["avatar_url"] = "/favicon.png"
|
||||
project["name"] = project["name"].replace("_", " ").replace("-", " ")
|
||||
|
||||
|
||||
# Sort by last updated
|
||||
projects_sorted = sorted(projects, key=lambda x: x.get("updated_at", ""), reverse=True)
|
||||
|
||||
|
||||
# Remove duplicates by name
|
||||
seen_names = set()
|
||||
unique_projects = []
|
||||
@@ -152,7 +152,7 @@ def get_projects(limit=3):
|
||||
if project["name"] not in seen_names:
|
||||
unique_projects.append(project)
|
||||
seen_names.add(project["name"])
|
||||
|
||||
|
||||
_projects_cache = {"data": unique_projects, "timestamp": current_time}
|
||||
return unique_projects[:limit]
|
||||
except Exception as e:
|
||||
@@ -170,17 +170,17 @@ _uptime_ttl = 300 # 5 minutes cache
|
||||
def get_uptime_status():
|
||||
"""
|
||||
Get uptime status with caching (5 minute TTL).
|
||||
|
||||
|
||||
Returns:
|
||||
bool: True if services are up, False otherwise
|
||||
"""
|
||||
global _uptime_cache
|
||||
current_time = datetime.datetime.now().timestamp()
|
||||
|
||||
|
||||
# Check if cache is valid
|
||||
if _uptime_cache["data"] is not None and (current_time - _uptime_cache["timestamp"]) < _uptime_ttl:
|
||||
return _uptime_cache["data"]
|
||||
|
||||
|
||||
# Fetch new data
|
||||
try:
|
||||
uptime = requests.get(
|
||||
@@ -204,7 +204,7 @@ def get_uptime_status():
|
||||
def get_wallet_tokens():
|
||||
"""
|
||||
Get wallet tokens with caching.
|
||||
|
||||
|
||||
Returns:
|
||||
list: List of token dictionaries
|
||||
"""
|
||||
@@ -220,7 +220,7 @@ def get_wallet_tokens():
|
||||
def get_coin_names():
|
||||
"""
|
||||
Get coin names with caching.
|
||||
|
||||
|
||||
Returns:
|
||||
dict: Dictionary of coin names
|
||||
"""
|
||||
@@ -236,7 +236,7 @@ def get_coin_names():
|
||||
def get_wallet_domains():
|
||||
"""
|
||||
Get wallet domains with caching.
|
||||
|
||||
|
||||
Returns:
|
||||
dict: Dictionary of wallet domains
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user