GreedyDatabaseBackend

readonly class \TYPO3\CMS\Core\Domain\Persistence\GreedyDatabaseBackend

Fetches all records of a single table of one / multiple PID(s) in one DB query, and stores them in a runtime cache.

The records are neither grouped nor do we care about

  • sorting
  • limit / offset
  • or BE User permissions.

It is "greedy" because it is meant to do simple query in a fast way, to reduce overlays on a "per record" basis.

The records are fetched depending on

  • fe_group permissions
  • language (incl. overlays etc)
  • workspace
  • visibility restrictions (starttime / endtime / hidden / deleted)

The class returns an array and does not handle objects, as it is very "lowlevel" and thus: internal.

Table of Contents

Properties

$connectionPool  : ConnectionPool
$recordAccessVoter  : RecordAccessVoter
$runtimeCache  : FrontendInterface

Methods

__construct()  : mixed
getRows()  : array
createRowsCacheIdentifier()  : string
Identifier of the cache entry holding all accessible rows of one pid.
createRuntimeCacheIdentifier()  : string
createUidPointerCacheIdentifier()  : string
Identifier of the pointer entry telling on which pid the row of a uid has been found, or "false" if the uid has no accessible row.
getRowsFromCache()  : array
Collects the rows of the given uids from the pid based cache entries. The uids may be spread over any number of pids, so all pointed to result sets are taken into account.
getRowsFromDatabase()  : array
handleOverlays()  : array
isResolvableFromCache()  : bool
The greedy result sets are stored per pid, and each uid points to the pid its row has been found on. A uid is answerable from the runtime cache if that pointer exists and the row set of the pid it points to is still cached. Requested uids without an accessible row are pointed to "false", so they do not trigger a database query over and over again.
setCache()  : void
Splits the greedy result set into one cache entry per pid, and creates a lightweight pointer from each uid to the pid its row belongs to.

Properties

Methods

getRows()

public getRows(string $tableName, array $uids, Context $context) : array

Parameters

$tableName : string
$uids : array
$context : Context

Return values

array

createRowsCacheIdentifier()

Identifier of the cache entry holding all accessible rows of one pid.

protected createRowsCacheIdentifier(string $tableName, int $pid, Context $context) : string

Parameters

$tableName : string
$pid : int
$context : Context

Return values

string

createRuntimeCacheIdentifier()

protected createRuntimeCacheIdentifier(string $tableName, string $entryKey, Context $context) : string

Parameters

$tableName : string
$entryKey : string
$context : Context

Return values

string

createUidPointerCacheIdentifier()

Identifier of the pointer entry telling on which pid the row of a uid has been found, or "false" if the uid has no accessible row.

protected createUidPointerCacheIdentifier(string $tableName, int $uid, Context $context) : string

Parameters

$tableName : string
$uid : int
$context : Context

Return values

string

getRowsFromCache()

Collects the rows of the given uids from the pid based cache entries. The uids may be spread over any number of pids, so all pointed to result sets are taken into account.

protected getRowsFromCache(string $tableName, array $uids, Context $context) : array

The rows are returned in the order of the given uids.

Parameters

$tableName : string
$uids : array
$context : Context

Return values

array

getRowsFromDatabase()

protected getRowsFromDatabase(string $tableName, array $uids, Context $context) : array

Parameters

$tableName : string
$uids : array
$context : Context

Return values

array

handleOverlays()

protected handleOverlays(array $rows, string $dbTable, Context $context) : array

Parameters

$rows : array
$dbTable : string
$context : Context

Return values

array

isResolvableFromCache()

The greedy result sets are stored per pid, and each uid points to the pid its row has been found on. A uid is answerable from the runtime cache if that pointer exists and the row set of the pid it points to is still cached. Requested uids without an accessible row are pointed to "false", so they do not trigger a database query over and over again.

protected isResolvableFromCache(string $tableName, int $uid, Context $context) : bool

Parameters

$tableName : string
$uid : int
$context : Context

Return values

bool

setCache()

Splits the greedy result set into one cache entry per pid, and creates a lightweight pointer from each uid to the pid its row belongs to.

protected setCache(string $tableName, array $uids, Context $context, array $allRows) : void

The rows of a pid are complete: the greedy query fetches all accessible records of the pids of the given uids, so a pid based cache entry can be reused for any later request of any record on that pid - no matter which uids that request combines.

Example: Having 1000 records on the same pid with each having a relation to a file reference. When RecordFactory is used to resolve all of these 1000 records at a time, each of these 1000 relations would produce a cache entry with 1000 file reference database rows (1000*1000 = 1.000.000 database rows).

Instead, only 1 cache entry is created with 1000 database rows and in addition 1000 lightweight cache identifier pointers, pointing to that pid.

Parameters

$tableName : string
$uids : array
$context : Context
$allRows : array
On this page