ID_LENGTH
ID_LENGTH = 12
How many hex characters of the derived digest the id uses.
Short enough to keep keys readable, long enough that two sites in one bucket will not collide.
Which site's history a read or a write belongs to.
Several sites can share one bucket, and often should: dedup is per-frame and content-addressed, so two sites running the same modules share the frames for their identical config and code, and the second site's code realm costs almost nothing. What they must not share is history. A commit is a statement about one site at one instant, and a ref that two sites both advanced would describe neither.
So every key is prefixed with a site id and every ref lives under it. A restore reads only its own site's refs; a prune walks only its own site's commits. Frames stay shared, because a frame is content and content has no owner.
The site id is derived once and then fixed. It defaults to a digest of the database connection's own identity - the database name and the table prefix - because that is what actually distinguishes two sites sharing a codebase, and because it does not change when a domain does. A site that moves to a new database keeps its history by setting the id explicitly, which is exactly the case where deriving it again would silently start a second history.
__construct(\Drupal\Core\Config\ConfigFactoryInterface $configFactory, \Drupal\Core\Database\Connection $database) : mixed
Constructs a context.
| \Drupal\Core\Config\ConfigFactoryInterface | $configFactory | Where a configured site id is read from. |
| \Drupal\Core\Database\Connection | $database | Used to derive an id when none is configured. |
strip(string $key) : string|null
Strips this site's prefix off a key.
| string | $key | The full key. |
The key relative to the site, or NULL when the key belongs to a different site. Returning NULL rather than the key unchanged is what stops a listing over a shared bucket quietly handing one site another's commits.
normalise(string $id) : string
Reduces a configured id to something safe in an object key.
A site id ends up in every key this site writes, so a slash or a traversal segment in it would let one site write into another's namespace.
| string | $id | The configured id. |
The id with everything but letters, digits, hyphens and underscores removed.
derive() : string
An id derived from the database connection's identity.
The database name and table prefix together are what distinguishes two Drupal sites sharing a codebase, which is the multi-site case this exists for. A domain is not used: it changes when a site is renamed or moved behind a different host, and a changed site id means a second history.
The derived id.