Skip to content

Commit 44c7ef4

Browse files
committed
correct cache
1 parent 66a84ec commit 44c7ef4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

website/app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ def serve_js(filename):
3333
@app.route('/api/community_projects/')
3434
def community_projects():
3535
global community_projects_cache
36-
if time.time() - 300 > last_cache_time:
36+
global last_cache_time
37+
if time.time() > last_cache_time + 300:
3738
projects = sa.Studio(id=31478892).projects(limit=40)
3839
if isinstance(projects[0], dict): #atm the server this is running on still uses scratchattach 1.7.4 that returns a list of dicts here
3940
community_projects_cache = [
@@ -43,4 +44,5 @@ def community_projects():
4344
community_projects_cache = [
4445
{"project_id":p.id, "title":p.title, "author":p.author_name, "thumbnail_url":f"https://uploads.scratch.mit.edu/get_image/project/{p.id}_480x360.png"} for p in projects
4546
]
47+
last_cache_time = time.time()
4648
return jsonify(random.choices(community_projects_cache, k=5))

0 commit comments

Comments
 (0)