Env var - PAGE_WATCH_LIMIT enhancements (#4359)

This commit is contained in:
dgtlmoon
2026-09-02 13:37:55 +02:00
committed by GitHub
parent af234636b9
commit 68a445df1b
41 changed files with 290 additions and 117 deletions
+9
View File
@@ -194,6 +194,15 @@ class Import(Resource):
urls_to_import.append(url)
# PAGE_WATCH_LIMIT - refuse the whole batch rather than importing an arbitrary prefix of
# it, so a 429 always means "nothing was created" and the caller can retry as-is
watch_limit = self.datastore.watch_limit
if watch_limit is not None:
current_watch_count = len(self.datastore.data['watching'])
if current_watch_count + len(urls_to_import) > watch_limit:
return (f"Watch limit reached ({current_watch_count}/{watch_limit} watches), importing "
f"{len(urls_to_import)} URL(s) would exceed it. No watches were imported.", 429)
# For small imports, process synchronously for immediate feedback
if len(urls_to_import) < IMPORT_SWITCH_TO_BACKGROUND_THRESHOLD:
added = []
+6 -10
View File
@@ -560,6 +560,12 @@ class CreateWatch(Resource):
del extras['url']
# PAGE_WATCH_LIMIT - checked up front so a blocked add is reported as 429 rather than
# being guessed at from add_watch() returning None
if self.datastore.watch_limit_reached():
current_watch_count = len(self.datastore.data['watching'])
return f"Watch limit reached ({current_watch_count}/{self.datastore.watch_limit} watches). Cannot add more watches.", 429
new_uuid = self.datastore.add_watch(url=url, extras=extras, tag=tags)
# Save processor config to separate JSON file
@@ -570,16 +576,6 @@ class CreateWatch(Resource):
# worker_pool.queue_item_async_safe(self.update_q, queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': new_uuid}))
return {'uuid': new_uuid}, 201
else:
# Check if it was a limit issue
page_watch_limit = os.getenv('PAGE_WATCH_LIMIT')
if page_watch_limit:
try:
page_watch_limit = int(page_watch_limit)
current_watch_count = len(self.datastore.data['watching'])
if current_watch_count >= page_watch_limit:
return f"Watch limit reached ({current_watch_count}/{page_watch_limit} watches). Cannot add more watches.", 429
except ValueError:
pass
return "Invalid or unsupported URL", 400
@auth.check_token