Skip to content

Audit & simplify the operations layer (dedup, generic passthrough, aligned APIs, ping latency, source consistency) #49

Description

@kfastov

After routing all commands through the warm server (#48), core/operations.js (44 ops) has several smells to audit and fix:

  • Boilerplate duplication. messagesGet and messagesContext repeat the same resolveSource + fetchLive + live/both/archive/live-fallback if-chain almost verbatim (likely messagesList/messagesSearch too). Consolidate the source-resolution + fallback pattern into one shared helper.
  • Thin passthroughs. ~23 ops are one-line forwards to ctx.telegramClient / ctx.messageSyncService. Don't hand-write a wrapper per method — expose the client methods generically (a passthrough mechanism, adjusting the client API if needed) and hand-write only the composite ops.
  • API adaptation that shouldn't exist. CLI handlers build per-op args objects mapping CLI options to op params (e.g. messagesSearch maps ~12 fields; same in runSendText). We control both sides — align the internal/CLI API so a command's params pass through as ONE object, no per-call adaptation. Collapsing these turns many ops into thin wrappers forwardable by one mechanism.
  • Pre-invoke ping latency. runOperationensureServer PINGs the server (1 round-trip) before invoke (another round-trip) on EVERY command — 2 loopback RTs on the warm path. Optimize: invoke directly; only start the server on a connection failure (ECONNREFUSED / missing control.json). Saves a RT per command.
  • Minimize Telegram API calls. Audit each op's TG request count and reduce round-trips (e.g. repeated metadata lookups).
  • Live/archive consistency. Within a single messagesContext/messagesGet call, target + context come from one source (good). Audit the --source archive→live fallback (usedLiveFallback) and the cross-command risk: search hits from live then context from archive = inconsistent snapshot. Document/guard so results aren't silently mixed.

Refs: core/operations.js, core/command-context.js (runOperation), core/control-client.js (ensureServer). Related: #43 (thin handlers), #40 (bicycles).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions