Re-send instance name requests every day when they're needed
This commit is contained in:
parent
f814d38af9
commit
acf718c676
1 changed files with 24 additions and 4 deletions
28
main.py
28
main.py
|
@ -1,8 +1,7 @@
|
||||||
from quart import Quart, request, render_template, redirect
|
from quart import Quart, request, render_template, redirect
|
||||||
|
from datetime import datetime
|
||||||
import peertube
|
import peertube
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
commit = "not found"
|
commit = "not found"
|
||||||
with open(".git/refs/heads/main") as file:
|
with open(".git/refs/heads/main") as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
|
@ -48,14 +47,35 @@ class VideoWrapper:
|
||||||
self.no_quality_selected = not self.video
|
self.no_quality_selected = not self.video
|
||||||
|
|
||||||
|
|
||||||
|
# Format:
|
||||||
|
# key: domain
|
||||||
|
# entry: [ instance_name, last_time_updated ]
|
||||||
cached_instance_names = {}
|
cached_instance_names = {}
|
||||||
|
|
||||||
# cache the instance names so we don't have to send a request to the domain every time someone
|
# cache the instance names so we don't have to send a request to the domain every time someone
|
||||||
# loads any site
|
# loads any site
|
||||||
def get_instance_name(domain):
|
def get_instance_name(domain):
|
||||||
if domain in cached_instance_names:
|
if domain in cached_instance_names:
|
||||||
return cached_instance_names[domain]
|
last_time_updated = (cached_instance_names[domain])[1]
|
||||||
return peertube.get_instance_name(domain)
|
time_diff = datetime.now() - last_time_updated
|
||||||
|
|
||||||
|
# only check once every day
|
||||||
|
if time_diff.days != 0:
|
||||||
|
cached_instance_names[domain] = [
|
||||||
|
peertube.get_instance_name(domain),
|
||||||
|
datetime.now()
|
||||||
|
]
|
||||||
|
else:
|
||||||
|
cached_instance_names[domain] = [
|
||||||
|
peertube.get_instance_name(domain),
|
||||||
|
datetime.now()
|
||||||
|
]
|
||||||
|
|
||||||
|
return (cached_instance_names[domain])[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app = Quart(__name__)
|
app = Quart(__name__)
|
||||||
|
|
Loading…
Reference in a new issue