Skip to content

comicbox.online_estimate ¶

Estimate the API-request count and wall-clock for a batch online-tag run.

A batch caller (Codex) shows this to an operator before a “Tag Online” run and mirrors it in a live countdown. Keeping the model here — next to the search flow it describes and the rate limits it divides by — means the numbers move with comicbox’s behavior instead of drifting in a downstream copy.

The model is deliberately simple. Per comic, each source costs a characteristic number of API requests:

  • Metron resolves an issue with a single issues_list search plus the final issue fetch — a flat count (see v4.0.5 / PR #143; no series-discovery step since series ids land directly on issue-list results). Metron does not fan out, so effort does not move it.
  • Comic Vine discovers volumes, asks each surviving candidate for its issues, then fetches the issue it accepts. Only the middle step varies: Effort decides how many candidates are worth a call.
  • VerseDB searches series, lists the issues of every surviving series in one call, then fetches the issue it accepts — a flat count, like Metron’s. Its free tier’s 300/hour cap paces it; the 4,000/day cap is not modelled, as no source’s daily cap is.

Match mode is not an input. It decides how a verdict is applied, never how many requests a search spends.

Under first-match-wins a comic stops at the first source that answers, so the run is billed the costliest single selected source; merging all sources (first_wins=False) queries every source per comic, so their per-comic costs are summed.

Wall-clock paces each source at its sustained throughput: Metron’s per-minute cap binds a bounded run directly. Comic Vine limits per resource pool — 200/hour for each endpoint (simyan keeps a separate bucket per endpoint, mirroring CV’s documented “200 requests per resource per hour”) — so a run is bound by its busiest single pool, not by the request total: discovery and the final fetches each land in their own pool while the per-volume issue lookups stack in one. first-match-wins means a comic isn’t done until the binding source answers, so the slowest source sets the pace; merging pays every source per comic, so their paces sum.

The projection prices a cold search for every comic. A real run batches by series, where one search answers for the whole series and the issues after it cost about one issue-list call each, so a library finishes ahead of this number. Each call counted here is one HTTP request: simyan 4.1.0 stops paginating on a short page, so a Comic Vine list call no longer spends two of its pool’s hourly budget (Simyan#309, see tasks/simyan-4-plan.md).

RunEstimate dataclass ¶

The projected cost of a batch online-tag run.

Source code in comicbox/online_estimate.py
145
146
147
148
149
150
151
152
@dataclass(frozen=True, slots=True)
class RunEstimate:
    """The projected cost of a batch online-tag run."""

    requests: int
    """Total API requests the run is expected to make."""
    seconds: float
    """Projected wall-clock duration in seconds."""

requests instance-attribute ¶

Total API requests the run is expected to make.

seconds instance-attribute ¶

Projected wall-clock duration in seconds.

estimate_run(comics, sources, *, effort=Effort.BALANCED.value, merge_all_sources=False) ¶

Project the request count and wall-clock seconds for a batch online-tag run.

comics is how many comics remain to look up and sources the enabled source names in priority order. effort is an :class:~comicbox.config.online.settings.Effort value ("balanced" etc.), resolved for the source it prices. merge_all_sources mirrors first_wins=False: every source is queried per comic and their per-comic costs summed, instead of stopping at the first match.

The projection assumes the effort it is handed. A CLI run can auto-engage a lower Comic Vine effort for a large unattended batch, which this cannot see.

Source code in comicbox/online_estimate.py
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
def estimate_run(
    comics: int,
    sources: Sequence[str],
    *,
    effort: str = Effort.BALANCED.value,
    merge_all_sources: bool = False,
) -> RunEstimate:
    """
    Project the request count and wall-clock seconds for a batch online-tag run.

    ``comics`` is how many comics remain to look up and ``sources`` the
    enabled source names in priority order. ``effort`` is an
    :class:`~comicbox.config.online.settings.Effort` value (``"balanced"``
    etc.), resolved for the source it prices. ``merge_all_sources`` mirrors
    ``first_wins=False``: every source is queried per comic and their
    per-comic costs summed, instead of stopping at the first match.

    The projection assumes the effort it is handed. A CLI run can
    auto-engage a lower Comic Vine effort for a large unattended batch,
    which this cannot see.
    """
    sources = tuple(sources)
    if comics <= 0 or not sources:
        return RunEstimate(requests=0, seconds=0.0)
    per_source = [requests_per_comic(source, effort) for source in sources]
    # Merge sums every source's per-comic cost; first-match-wins bills the
    # costliest single source the run might hit.
    per_comic = sum(per_source) if merge_all_sources else max(per_source)
    requests = comics * per_comic
    # Merge pays every source per comic; first-match-wins isn't done until
    # the binding (slowest) source answers.
    paces = [_seconds_per_comic(source, effort) for source in sources]
    seconds_per_comic = sum(paces) if merge_all_sources else max(paces)
    return RunEstimate(requests=requests, seconds=comics * seconds_per_comic)

metron_requests_for_batch(comics, series) ¶

Return what a Metron batch of comics over series runs costs.

The per-comic constant prices a comic that resolves its own series. That is the right number for a scattered batch and badly wrong for a library-scale one, where one series answers for a hundred comics: each series pays the cold price once and every other comic of it pays the warm price.

series is how many distinct series the batch spans — the CLI and OnlineSession.tag_many both count them to decide prefetching, so the caller has the number already. Clamped into range, since a batch cannot span more series than it has comics.

Source code in comicbox/online_estimate.py
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def metron_requests_for_batch(comics: int, series: int) -> int:
    """
    Return what a Metron batch of ``comics`` over ``series`` runs costs.

    The per-comic constant prices a comic that resolves its own series.
    That is the right number for a scattered batch and badly wrong for a
    library-scale one, where one series answers for a hundred comics:
    each series pays the cold price once and every other comic of it pays
    the warm price.

    ``series`` is how many distinct series the batch spans — the CLI and
    `OnlineSession.tag_many` both count them to decide prefetching, so
    the caller has the number already. Clamped into range, since a batch
    cannot span more series than it has comics.
    """
    if comics <= 0:
        return 0
    series = max(1, min(series, comics))
    cold = series * METRON_REQUESTS_PER_COMIC
    warm = (comics - series) * METRON_REQUESTS_PER_WARM_COMIC
    return cold + warm

requests_per_comic(source, effort=Effort.BALANCED.value) ¶

Return the API requests one comic costs against source at effort.

effort is an :class:~comicbox.config.online.settings.Effort or its value. Resolve it for the source it prices — resolve_effort(settings.online, "comicvine") — because a per-source override beats the global setting.

Source code in comicbox/online_estimate.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
def requests_per_comic(source: str, effort: str = Effort.BALANCED.value) -> int:
    """
    Return the API requests one comic costs against ``source`` at ``effort``.

    ``effort`` is an :class:`~comicbox.config.online.settings.Effort` or its
    value. Resolve it for the source it prices —
    ``resolve_effort(settings.online, "comicvine")`` — because a per-source
    override beats the global setting.
    """
    if source == "metron":
        return METRON_REQUESTS_PER_COMIC
    if source == "comicvine":
        return (
            COMICVINE_DISCOVERY_REQUESTS
            + _comicvine_issue_list_requests(effort)
            + COMICVINE_FETCH_REQUESTS
        )
    if source == "versedb":
        return VERSEDB_REQUESTS_PER_COMIC
    return DEFAULT_REQUESTS_PER_COMIC

source_rate_per_minute(source) ¶

Return the pace to project a run at, preferring the server’s number.

SOURCE_RATE_PER_MINUTE holds documented starting points. Metron sends its real per-user burst limit on every response, and comicbox’s rate gate paces against that, so once anything has talked to Metron in this process the gate’s number is the one a projection should use — a self-hosted instance or a changed server setting makes the constant simply wrong.

Source code in comicbox/online_estimate.py
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
def source_rate_per_minute(source: str) -> int:
    """
    Return the pace to project a run at, preferring the server's number.

    `SOURCE_RATE_PER_MINUTE` holds documented starting points. Metron
    sends its real per-user burst limit on every response, and comicbox's
    rate gate paces against that, so once anything has talked to Metron
    in this process the gate's number is the one a projection should use
    — a self-hosted instance or a changed server setting makes the
    constant simply wrong.
    """
    if source == "metron":
        limit = _metron_gate_limit()
        if limit is not None:
            return limit
    return SOURCE_RATE_PER_MINUTE.get(source, DEFAULT_RATE_PER_MINUTE)