Skip to content

fix: no delay between batch jobs#739

Open
ayubun wants to merge 1 commit intovictornpb:masterfrom
ayubun:search-delay-for-jobs
Open

fix: no delay between batch jobs#739
ayubun wants to merge 1 commit intovictornpb:masterfrom
ayubun:search-delay-for-jobs

Conversation

@ayubun
Copy link
Copy Markdown

@ayubun ayubun commented Nov 7, 2025

when running batch jobs, the first api search for each job does not have any search delay. this is not a problem when running a single job, but when there are subsequent jobs, it will spam the api:

image

i believe this is a remnant of the code pre-batching, where such a delay is unneeded. i've added a simple check to apply a jobDelay before running if the current job is not the first one.

i'm not keen on making frontend changes so this option is currently backend only; i'd rather it be supported without UX to change it than to spam jobs >.<


note: my personal contributions to and usage of this project do not represent discord. opinions are my own

@ayubun ayubun force-pushed the search-delay-for-jobs branch from 735dd6e to 1aba4cc Compare November 7, 2025 00:58
@ayubun ayubun changed the title fix: wait searchDelay between batch jobs fix: no searchDelay between batch jobs Nov 7, 2025
@ayubun ayubun force-pushed the search-delay-for-jobs branch 2 times, most recently from 8ebd94c to 82b61fd Compare November 8, 2025 00:06
@ayubun ayubun changed the title fix: no searchDelay between batch jobs fix: no delay between batch jobs Nov 8, 2025
@ayubun ayubun force-pushed the search-delay-for-jobs branch from 82b61fd to 12d0182 Compare November 8, 2025 01:30
TheCellMaster added a commit to TheCellMaster/undiscord that referenced this pull request Apr 15, 2026
Major refactor: modular architecture + upstream PR features + security fixes.

=== ARCHITECTURE (complete rewrite) ===
- Split monolithic undiscord-core.js (584 lines) into 5 focused modules:
  - src/core/undiscord-core.js: Orchestrator (run, runBatch, stop, confirm)
  - src/core/search.js: Search with iterative retry (202/429 handling)
  - src/core/filter.js: Pure message filtering (types, pinned, bots, threads, regex)
  - src/core/delete.js: Delete with retry loop + rate limit adaptation
  - src/core/unarchive.js: Thread unarchive before delete
- Split monolithic undiscord-ui.js (378 lines) into 4 modules:
  - src/ui/init.js: DOM mount, CSS injection, toolbar button + MutationObserver
  - src/ui/handlers.js: All event handlers (start, stop, getChannel, pick, etc)
  - src/ui/progress.js: onStart/onProgress/onStop callbacks
  - src/ui/logger.js: XSS-safe log rendering with ring buffer
- Created src/api/discord-api.js: Pure fetch layer with AbortSignal.timeout(30s)
- Split helpers.js (8 functions in 8 lines) into semantic modules:
  - src/utils/time.js: wait(), msToHMS()
  - src/utils/html.js: escapeHTML(), redact(), replaceInterpolations()
  - src/utils/discord.js: queryString(), ask(), toSnowflake()
- Merged createElm.js + insertCss.js into src/utils/dom.js
- Split CSS (theme.css 355 lines + main.css 172 lines) into 6 modules:
  - layout.css, components.css, scrollbar.css, redact.css, log.css, drag.css
- Moved HTML templates to src/ui/html/
- Renamed utils to kebab-case (getIds -> get-ids, messagePicker -> message-picker)
- Removed 12 legacy files replaced by modular architecture
- Created src/utils/constants.js with shared constants

=== NEW FEATURES (from upstream PRs) ===
- victornpb#741: Poll messages (type 46) can now be deleted
- victornpb#741: Bot slash command responses (type 20) excluded from deletion
- victornpb#742: HTTP 403 on delete returns FAIL_SKIP instead of infinite retry loop
- victornpb#743: Retry logic refactored: FAILED/FAIL_SKIP properly handled, failCount centralized
- victornpb#740: HTTP 403 on search gracefully skips channel instead of canceling batch
- victornpb#739: 30s delay between batch jobs to prevent API spam
- victornpb#737: Thread unarchiving: attempts PATCH to unarchive before skipping
- victornpb#729: Empty page retries (configurable, default 2) before stopping
- victornpb#629: "Include bot/application messages" checkbox in Filter section
- victornpb#610: Thread auto-detection via API when clicking "current" channel button
- victornpb#603: Graceful handling of API errors 50024 (channel not found) and 50001 (missing access)
- victornpb#643: Date filter warning: "Make sure you enter both date AND time"
- victornpb#527/victornpb#519: Rate limit delay adds on top (never decreases) with caps

=== SECURITY FIXES ===
- S1 XSS fix: printLog now escapes all external data via escapeHTML(),
  preserving <x> redact tags via split pattern for streamer mode
- escapeHTML() now also escapes > character
- Log type validated against whitelist before becoming CSS class name
- AbortSignal.timeout(30s) on ALL fetch calls (search, delete, unarchive, getChannel)
  replacing leaky setTimeout-based AbortController
- retry_after clamped with Math.max(w, 0) to prevent negative values causing tight loops

=== BUG FIXES ===
- Fixed onStop called twice (stop() + end of run()) via guard check
- Fixed missing return DELETE_RESULT.FAILED in JSON.parse catch path
- Fixed filterResponse was async unnecessarily (now sync)
- Fixed _searchResponse null crash with guard in filterResponse
- Fixed .filter(Boolean) after map().find() to prevent undefined entries
- Fixed replaceInterpolations treating falsy values (0, false, "") as missing (|| -> ??)

=== QUALITY IMPROVEMENTS ===
- DELETE_RESULT enum (Object.freeze) replaces magic strings
- DELETABLE_MSG_TYPES Set replaces compound conditional
- Set-based lookup for skipped messages (O(n) vs O(n^2))
- search() converted from recursive to iterative with MAX_SEARCH_RETRIES=20
- searchDelay capped at MAX_SEARCH_DELAY_MS (60s)
- deleteDelay capped at MAX_DELETE_DELAY_MS (30s)
- Log ring buffer: MAX_LOG_ENTRIES=5000 prevents unbounded DOM growth
- Confirm preview limited to 10 messages
- messagePicker timeout (30s) with automatic cleanup
- drag.css selectors scoped with #undiscord
- .resize-handle scoped with #undiscord
- Orphan .logarea CSS class removed
- MutationObserver throttle extracted to OBSERVER_THROTTLE_MS constant
- All CSS variables use fallback pattern var(--new, var(--old))
- JSDoc on all public methods

=== BUILD ===
- metadata.mjs supports contributors array from package.json
- @author now shows both victornpb and TheCellMaster
- CLAUDE.md created with project documentation

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant