Repository navigation
feat(grabber): a site remembers a programme's details between runs - #30
Merged
Merged
Conversation
A source that wants a request per programme for its details makes a nightly
refetch expensive. Today is fetched again every run, and with it every detail
call for programmes already asked about. homepi carries the same forty lines
in three sites to avoid it, and webtv.sk went from 9,643 requests a cold day
to 1,543.
Every context a site is handed now has `remember(key, { until, miss? }, task)`,
which answers with what an earlier run kept under the key, or with the task's
answer, kept until `until`. A failure `miss` matches is kept as `null`, so
"no details" is asked once; any other is thrown and not kept, so the next run
asks again. A kept "none" is an answer only to an ask with a `miss` of its
own, which is what lets the type leave `null` out when there is none.
Two asks of one key while the first is on its way are one task, each reading
what it came to with its own `miss`. A parse waiting on another's lends its
slot meanwhile, as it does for `paced`; a request cannot lend its queue slot,
so it asks for itself. Every caller is handed a copy.
Values are kept in a state group of their own, `remembered`, beside the
site's `state`, and what has passed its `until` is dropped at the end of every
run, whether or not anything asked. `--refresh` reads nothing kept and still
keeps. An `until` already past keeps a value for this run only, and says so
once. A value must be plain, as a channel's data must, since it comes back
from JSON. A site state read that fails is no longer kept as the group, so
the next ask tries again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A site can now keep what it asked a source for between runs, so a nightly refetch doesn't ask for every programme's details again. homepi asked for this: three of its sites carry the same ~40 lines to do it by hand, and with them webtv.sk went from 9,643 requests a cold day to 1,543. One commit, a feature.
ctx.remember(key, { until, miss? }, task)Every context a site is handed has it: requests,
parseDay, and a stream's pass. It answers with what an earlier run kept underkey, or runstaskand keeps its answer untiluntil.untilis required, aDateor epoch milliseconds, since how long something is worth keeping is the site's to say. One already past keeps the value for this run only, with one warning per run; it usually means seconds where milliseconds were meant.missturns a failure into a keptnull, so "no details" is asked once. Any other failure is thrown and not kept, so the next run asks again.nullin it only when the ask has amiss. A "none" kept for an ask with amissis never handed to one without; that ask runs its own task.datamust. ADateor aMapis refused with the site, the key and where in the value. Each caller gets its own copy.Two asks at once
Two asks of one key while the first is still running share one task, and each reads the outcome with its own
miss. That covers a broadcast past midnight, which appears in two days' listings. A parse waiting on another parse's ask gives up itslocalWorkslot meanwhile, as it does forpaced, solocalConcurrency: 1can't deadlock. A request can't give up its site-queue slot yet, so it asks for itself instead of waiting.Storage
remembered, beside the site'sstate, so a token isn't rewritten for the details' sake.--refreshreads nothing an earlier run kept, and still keeps new answers, as it does for cached listings.Smaller changes
src/core/plain.ts, sincerememberuses it too.StateKey.REMEMBEREDnames the new group, and the API docs now list all four state groups.Testing
miss, other failures and each caller's ownmiss;--refresh, a pastuntil, option validation, a failed read, and the return types.test/readme-examples.tsand typechecks.