Skip to content

Commit 93275ed

Browse files
committed
Speed bump: disabled dev path, more latency but better speed
1 parent 6745dd1 commit 93275ed

1 file changed

Lines changed: 7 additions & 30 deletions

File tree

src/relay/domain_fronter.py

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __init__(self, config: dict):
129129
self._script_ids = script if isinstance(script, list) else [script]
130130
self._script_idx = 0
131131
self.script_id = self._script_ids[0] # backward compat / logging
132-
self._dev_available = False # True if /dev endpoint works (no redirect, ~400ms faster)
132+
self._dev_available = False # Always False — /exec is used exclusively
133133
self._apps_script_lang = str(
134134
config.get("apps_script_lang", self._APPS_SCRIPT_DEFAULT_LANG)
135135
).strip().lower() or self._APPS_SCRIPT_DEFAULT_LANG
@@ -959,10 +959,10 @@ def _exec_path(self, url_or_host: str | None = None) -> str:
959959
return self._exec_path_for_sid(sid)
960960

961961
def _exec_path_for_sid(self, sid: str) -> str:
962-
"""Build the /macros/s/<sid>/(dev|exec) path for a specific script ID."""
963-
endpoint = "dev" if self._dev_available else "exec"
964-
# Force Google Apps Script UI/errors to English for stable diagnostics.
965-
return f"/macros/s/{sid}/{endpoint}?hl={self._apps_script_lang}"
962+
"""Build the /macros/s/<sid>/exec path for a specific script ID."""
963+
# Always use /exec (production endpoint). /dev is a test-deployment path
964+
# with unstable auth/latency behaviour and is not used in production.
965+
return f"/macros/s/{sid}/exec?hl={self._apps_script_lang}"
966966

967967
def _apps_script_headers(self) -> dict[str, str]:
968968
"""Headers for Apps Script relay calls (control-plane, not target origin)."""
@@ -1154,36 +1154,13 @@ async def _h2_connect_and_warm(self):
11541154
self._keepalive_task = self._spawn(self._keepalive_loop())
11551155

11561156
async def _prewarm_script(self):
1157-
"""Pre-warm Apps Script and detect /dev fast path (no redirect)."""
1157+
"""Pre-warm Apps Script via /exec."""
11581158
payload = json.dumps(
11591159
{"m": "GET", "u": "http://example.com/", "k": self.auth_key}
11601160
).encode()
11611161
hdrs = self._apps_script_headers()
11621162
sid = self._script_ids[0]
11631163

1164-
# Test /dev endpoint — returns data inline (no 302 redirect).
1165-
# If it works, saves ~400ms per request by eliminating one round trip.
1166-
try:
1167-
dev_path = f"/macros/s/{sid}/dev?hl={self._apps_script_lang}"
1168-
t0 = time.perf_counter()
1169-
self._record_execution(sid)
1170-
status, _, body = await asyncio.wait_for(
1171-
self._h2.request(
1172-
method="POST", path=dev_path, host=self.http_host,
1173-
headers=hdrs, body=payload,
1174-
),
1175-
timeout=15,
1176-
)
1177-
dt = (time.perf_counter() - t0) * 1000
1178-
data = load_relay_json(body.decode(errors="replace"))
1179-
if "s" in data:
1180-
self._dev_available = True
1181-
log.info("/dev fast path active (%.0fms, no redirect)", dt)
1182-
return
1183-
except Exception as e:
1184-
log.debug("/dev test failed: %s", e)
1185-
1186-
# Fallback: warm up with /exec
11871164
try:
11881165
exec_path = f"/macros/s/{sid}/exec?hl={self._apps_script_lang}"
11891166
t0 = time.perf_counter()
@@ -1196,7 +1173,7 @@ async def _prewarm_script(self):
11961173
timeout=15,
11971174
)
11981175
dt = (time.perf_counter() - t0) * 1000
1199-
log.info("Apps Script pre-warmed in %.0fms", dt)
1176+
log.info("Apps Script pre-warmed via /exec in %.0fms", dt)
12001177
except Exception as e:
12011178
log.debug("Pre-warm failed: %s", e)
12021179

0 commit comments

Comments
 (0)