id of that other document in one of its attributes, and the document that id names is the referenced document:
- an order line reads its product
- a message reads its conversation
- a task reads its project
Define one
The relation’sjoin is {"theirs": "id", "mine": "attributes.<name>"}, where the judged document’s mine attribute holds the id of the referenced document.
Here each document of kind order_line points at a product through attributes.product_id:
applies_tosets which documents the judgment judges, answers and bills (here the order lines, not the products).- One document. The relation reads one document at most, so
related.producthas one record at most andcountis 0 or 1. It takes nowindow(awindowisinvalid_request), and with alast_nit reads a list of documents instead.match,fieldsandaggregatework as for any relation. - What it points at. The relation is empty when the
mineattribute is missing,nullor not a valid id, or names a document that does not agree withmatch. Brussle judges a document whose relation is empty. When the attribute names a document that does not exist, Brussle does not, as a missing referenced document explains. - One snapshot. Brussle reads the referenced document at the same point in the namespace’s writes as everything else, so the answer’s
watermarkalso says which revision of it the answer read, and the evaluation’srelated_documentsnames that revision. - Bands.
{"path": "state.stock", "bands": [1, 50], "labels": ["none", "low", "plenty"]}shows the band a number is in, so a stock of 0 shows asnoneand 1 to 49 aslow. A stock of 50 or more shows asplenty. A stock count that changes each day then changes what the order lines read only when it crosses a band. See bands. fanoutsets which order lines a change to the product re-judges. Here it is the open lines created in the 30 days before the change, at most 300,000 in any 30 days. See the controls.confirm. Brussle returns a replay estimate for a version withrelatedon anon_changejudgment, and creates nothing until you sendconfirm: true. What you confirm includes the rolling limit, and after that no fan-out waits for a person.
The reference index
Brussle finds the judged documents that point at a referenced document through a reference index on themine attribute. The first version that needs the index builds it with a reference_index job (the create response lists it in job_ids), and the judgment’s answers are unavailable until the job is done.
The index counts toward the 8 reference indexes a namespace can have, and an attribute that you use in more than one way is one index. A version that needs documents the index does not cover yet (one with a different applies_to, or one that uses the attribute in the other direction) gets a job that builds the index again, and its answers wait for that job in the same way.
Name several documents
The judged document can name a list of documents:- the invoices that a payment’s remittance advice names
- the clauses that a renewal depends on
- the listings that a complaint names
mine attribute, and a relation with a last_n reads the documents it names. Brussle calls this a named list:
invoice_ids names, in list order. Brussle judges again each payment that names an invoice when that invoice changes in a field the relation shows.
- In list order.
related.invoicesshows each named document once, at its first place, and at mostlast_nof them (last_nis 1 to 254). Anorder,{"by": "created_at"}included, sorts the documents beforelast_napplies.latestreads the newest by creation of the documents the relation shows. - What renders nothing. An id that names no document, or a document that does not agree with
match, renders nothing, and the evaluation’srelated_documentslists it withunresolved: true. Each document read is listed with itsrevision. Brussle ignores an entry that is not a valid document id. - Arrays and single ids. A relation with a
last_nreads arrays only, and one without reads a single id only, so each renders nothing for the other shape. - At most 254 ids. Once a judgment reads an attribute as a list, a write of more than 254 different ids to it is
invalid_request, and the error names the attribute. - Lists that are already too long. Brussle checks the existing documents at create. If a document holds more than 254 ids, the
reference_indexjob fails and names the documents, and the answers stayunavailable. Shorten those lists and create the version again. Arrays in attributes that no judgment reads as a list are not limited. - Fan-out. A change to any named document fans out to the documents that name it, with the same scope, debounce and rolling limit as a single referenced document. Each named document has its own debounce, so when several change at once, Brussle can judge a payment once for each of them.
- Cost. Each id in the list counts whatever
last_nshows, so a list of 254 ids is 254 documents whose changes can re-judge the payment. The replay estimate compiles its sample with each judged document’s list, so its size classes follow the lengths of your lists. - No
window. Brussle refuses one withinvalid_request.
Fan-out
A write to the referenced document re-judges each judged document that points at it and is inside the judgment’s re-judge scope, as long as the write changes what the relation shows. What a fan-out costs works through the numbers, so read it before you rely on a fan-out.The controls, in order of effect
The re-judge scope, bands and the fan-out debounce bring the cost down. The controls lists each one with its default.The rolling limit
The re-judges count against the judgment’s rolling limit, 300,000 in any 30 days by default. Past the limit the rest waits, and its answers readstale (limit_reached) until there is room (see the rolling limit).
What the answers show
- In scope. An answer is
pendingfrom the moment Brussle acknowledges the write to the referenced document, so no read after the acknowledgement sees itfreshagainst the old revision. It isfreshagain when an answer arrives with a watermark at or above the change. - A write that changes nothing shown. The answer stays
pendingonly until Brussle checks the write, a moment later, and is thenfreshagain with no engine call. - Deferred past the rolling limit. The answer is
stale, withstale_reasonlimit_reached, and the change in itsreferenced_changeshasdeferred: true. - Outside the scope. Nothing judges the answer again, so it reads
stalewithstale_reasonreferenced_changed, andanswers: "fresh_only"leaves it out. It keeps its numbers until Brussle judges the judged document again. - Only
on_changefans out. A change makes the answers in scopestaleunderperiodicandmanual, as any related write does, while underon_reada get or query of such an answer judges it again at once. updated_atchanges on each write. A relation that shows the referenced document’supdated_atfans out on every write to it, so the create response warns you.
- Its
watermarkand its evaluation’srelated_documentsgive that revision, so if the referenced document’srevisionis above the watermark, the answer read an earlier one. - On a get, the answer lists in
referenced_changesthe newest write to each document it points at that changed what the relation shows, with itsrevisionand time. - The next write to the judged document itself judges it again, against the referenced document as it is then.
A missing referenced document
Themine attribute can name a document that does not exist (you deleted it, or the id is wrong), and Brussle never judges the document as if the relation were empty:
- Only the referenced document changed: no engine call. The answer keeps the numbers of its last evaluation and reads
stale, withstale_reasonreferenced_missing, whatever the policy, and Brussle bills nothing for it. - The document itself or its other related documents changed: Brussle judges it. The relation’s entry in the context shows
missing: true, so the engine reads that the referenced document is gone. The answer gets the new numbers, is billed as any other, and still readsstale(referenced_missing). A project whose platform page you deleted still shows a blocker in its own new updates. - Say what a missing document means. Some engines read
missing: trueas a sign of risk and some do not, so if a document can be removed on purpose, say so in the question (for example, “If the platform page is shown as missing, it was removed on purpose: ignore it.”). Measure the answers with and without the sentence on your outcomes. You can also unset the reference attribute when you remove the document, which leaves the relation empty, and the answer can then readfresh. - Its numbers still count. Queries, thresholds and subscriptions read them as they read any
staleanswer, so an order line that a threshold flagged stays flagged.answers: "fresh_only"leaves the answer out. - A document that was never judged. Brussle does not judge such a document when you first write it, so it has no numbers. Its answer reads
stale(referenced_missing), and Brussle judges its next change, as above. - When it happens. The answers in scope read
pendingunderon_changeuntil the fan-out reaches them, thenreferenced_missing, and each counts toward the rolling limit. Underon_read, the first get or query after the delete holds the answer, and later reads do not judge it again. An answer outside the scope readsreferenced_changeduntil something judges the document again. - When the document comes back. Write a document with the same
id, and Brussle judges the answers again, since the write is a change to the referenced document. If the document shows the same as before the delete, and nothing else the answer reads changed in the meantime, the answers arefreshagain with no engine call. - Missing is not empty. An attribute that is missing,
nullor not a valid id names no document, so the relation is empty and Brussle judges the document. The same holds when the document exists but does not agree withmatch. - A named list is different. In a named list, an id that names no document renders nothing, and Brussle judges the document with the rest of the list.
The document a match picked
The document a judgment reads does not have to be in an attribute. It can be the one a matching judgment picked. The matching judgmentsettles picks the invoice a payment settles, and a payment judgment can read that invoice through a join on the answer of settles, behind one of its thresholds:
settles picked invoice 102 for this payment, below its unmatched threshold, so the payment judgment reads invoice 102 and none of the other invoices in its block.
The payment reads the invoice only when all of these are true:
settlesjudges the payment.- The current answer of
settlesnames the invoice, and theunmatchedthreshold isfalse. - The invoice is live, agrees with the relation’s
match, and has the same key as the payment.
last_n and no window, like any relation that reads one document. It requires when, and reads nothing else of the answer of settles.
Brussle judges the payment again in two cases:
- The pick changes.
settlespicks a different invoice for the payment, or starts or stops a link to it. A new answer that keeps the same pick causes nothing. - The invoice changes. A write fans out to the payments linked to the invoice, as a change to a referenced document does, when it changes what the relation shows of the invoice, whether the invoice is live or agrees with
match, or its key. The fan-out uses this judgment’s debounce, scope and rolling limit, and finds the payments in the invoice’s block through the answers ofsettles. A block with more documents than theblock_capofsettleswaits, as any block does. The payment readspendingfrom the moment Brussle acknowledges the write to its invoice.
Many-to-many, as membership documents
A user can be in many teams, so write one membership document for each pair of user and team, pointing at both withattributes.user_id and attributes.team_id. Then:
- a judgment on each membership reads its user as the referenced document
- a judgment on each team rolls up the answers of its memberships (roll-ups)
- The team judgment reads the membership judgment, so the membership judgment has no fan-out scope.
- A change to what the membership judgment shows of a user re-judges every membership of that user, for all time, and these re-judges count against the membership judgment’s rolling limit.
- Each membership whose band then changes re-judges its team, which counts against the team judgment’s rolling limit.
applies_to to keep ended memberships out, such as by judging only active ones.