Skip to content

Commit 22d8a89

Browse files
roed314claude
andcommitted
Remove the now-unreachable callback-AJAX machinery
With ajax_more and image_src gone, nothing calls ajax_url, so the callback pool and its route are unreachable: LinkedList, AjaxPool, pending, ajax_url, and the /callback_ajax/<id> endpoint. Removing them also frees the random and time imports and the app import in utilities.py, and makes the 'callback_ajax' entry in WhiteListedRoutes stale. image_callback stays: crystals and hypergm call it directly from their own image routes, not through the callback pool. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 2524035 commit 22d8a89

2 files changed

Lines changed: 1 addition & 94 deletions

File tree

lmfdb/app.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ def WhiteListedRoutes():
788788
'alive',
789789
'api',
790790
'bigpicture',
791-
'callback_ajax',
792791
'citation',
793792
'contact',
794793
'editorial-board',

lmfdb/utils/utilities.py

Lines changed: 1 addition & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import cmath
22
import math
33
import os
4-
import random
54
import re
65
import tempfile
7-
import time
86
from copy import copy
97
from itertools import islice
108
from types import GeneratorType
@@ -35,7 +33,7 @@
3533
from sage.misc.functional import round
3634
from sage.structure.element import Element
3735

38-
from lmfdb.app import app, is_beta, is_debug_mode, _url_source
36+
from lmfdb.app import is_beta, is_debug_mode, _url_source
3937

4038

4139
def integer_divisors(n):
@@ -802,96 +800,6 @@ def flash_success(msg, *args):
802800
flash(Markup(msg % tuple("<span style='color:black'>%s</span>" % escape(x) for x in args)), "success")
803801

804802

805-
################################################################################
806-
# Ajax utilities
807-
################################################################################
808-
809-
# LinkedList is used in Ajax below
810-
class LinkedList():
811-
__slots__ = ('value', 'next', 'timestamp')
812-
813-
def __init__(self, value, nxt):
814-
self.value = value
815-
self.next = nxt
816-
self.timestamp = time.time()
817-
818-
def append(self, value):
819-
self.next = LinkedList(value, self)
820-
return self.next
821-
822-
823-
class AjaxPool():
824-
def __init__(self, size=1e4, expiration=3600):
825-
self._size = size
826-
self._key_list = self._head = LinkedList(None, None)
827-
self._expiration = expiration
828-
self._all = {}
829-
830-
def get(self, key, value=None):
831-
return self._all.get(key, value)
832-
833-
def __contains__(self, key):
834-
return key in self._all
835-
836-
def __setitem__(self, key, value):
837-
self._key_list = self._key_list.append(key)
838-
self._all[key] = value
839-
840-
def __getitem__(self, key):
841-
res = self._all[key]
842-
self.purge()
843-
return res
844-
845-
def __delitem__(self, key):
846-
del self._all[key]
847-
848-
def pop_key(self):
849-
head = self._head
850-
if head.next is None:
851-
return None
852-
else:
853-
key = head.value
854-
self._head = head.next
855-
return key
856-
857-
def purge(self):
858-
if self._size:
859-
while len(self._all) > self._size:
860-
key = self.pop_key()
861-
if key in self._all:
862-
del self._all[key]
863-
if self._expiration:
864-
oldest = time.time() - self._expiration
865-
while self._head.timestamp < oldest:
866-
key = self.pop_key()
867-
if key in self._all:
868-
del self._all[key]
869-
870-
871-
pending = AjaxPool()
872-
def ajax_url(callback, *args, **kwds):
873-
if '_ajax_sticky' in kwds:
874-
_ajax_sticky = kwds.pop('_ajax_sticky')
875-
else:
876-
_ajax_sticky = False
877-
if not isinstance(args, tuple):
878-
args = args,
879-
nonce = hex(random.randint(0, 1 << 128))
880-
pending[nonce] = callback, args, kwds, _ajax_sticky
881-
return url_for('ajax_result', id=nonce)
882-
883-
884-
@app.route('/callback_ajax/<id>')
885-
def ajax_result(id):
886-
if id in pending:
887-
f, args, kwds, _ajax_sticky = pending[id]
888-
if not _ajax_sticky:
889-
del pending[id]
890-
return f(*args, **kwds)
891-
else:
892-
return "<expired>"
893-
894-
895803
def image_callback(G):
896804
P = G.plot()
897805
_, filename = tempfile.mkstemp('.png')

0 commit comments

Comments
 (0)