Skip to content

Commit

Permalink
Hopefully correct version of official-stockfish#2172.
Browse files Browse the repository at this point in the history
  • Loading branch information
vdbergh authored and ppigazzini committed Jan 16, 2025
1 parent d841075 commit 620979a
Showing 1 changed file with 1 addition and 39 deletions.
40 changes: 1 addition & 39 deletions server/fishtest/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,7 @@
HTTP_TIMEOUT = 15.0


def clear_cache():
global last_time, last_tests
building.acquire()
last_time = 0
last_tests = None
building.release()


def cached_flash(request, requestString, *l):
clear_cache()
request.session.flash(requestString, *l)
return

Expand Down Expand Up @@ -1729,15 +1720,6 @@ def homepage_results(request):
}


# For caching the homepage tests output
cache_time = 2
last_tests = None
last_time = 0

# Guard against parallel builds of main page
building = threading.Semaphore()


@view_config(route_name="tests", renderer="tests.mak")
def tests(request):
request.response.headerlist.extend(
Expand All @@ -1751,27 +1733,7 @@ def tests(request):
# page 2 and beyond only show finished test results
return get_paginated_finished_runs(request)

global last_tests, last_time
if time.time() - last_time > cache_time:
acquired = building.acquire(last_tests is None)
if not acquired:
# We have a current cache and another thread is rebuilding,
# so return the current cache
pass
elif time.time() - last_time < cache_time:
# Another thread has built the cache for us, so we are done
building.release()
else:
# Not cached, so calculate and fetch homepage results
try:
last_tests = homepage_results(request)
except Exception as e:
print("Overview exception: " + str(e))
if not last_tests:
raise e
finally:
last_time = time.time()
building.release()
last_tests = homepage_results(request)

return {
**last_tests,
Expand Down

0 comments on commit 620979a

Please sign in to comment.