class EntriesRepository

Constants

protected INDEX_FILE

protected LAST_PRUNE_FILE

Methods

__construct(string $path, int $autoPruneHours = 24, Filesystem $files = new Filesystem())

Create a new entries repository instance.

void
save(string $id, array $data)

Save the given entry payload.

array|null
get(string $id)

Get the payload of the given entry.

array
all()

All recorded entry metadata, newest first.

void
prune(int $hours)

Delete the entries recorded more than the given number of hours ago.

void
enforceTabLimit(string|null $tabUuid, int $limit)

Delete all but the given number of newest entries for the tab. Entries recorded without a tab, such as initial page loads and requests made without the extension, are limited as one group.

void
pruneIfDue()

Prune expired entries when the prune interval has elapsed.

void
ensureDirectory()

Ensure the storage directory and its .gitignore exist.

string
filePath(string $id)

Get the file path of the given entry.

bool
isValidEntryId(string $id)

Determine if the given entry id is valid.

string
indexPath()

Get the path of the index file.

string
lastPrunePath()

Get the path of the file recording the last prune time.

array
normalizeIndexMeta(array $meta)

Normalize an entry's __meta for storage in the index. The full meta is kept so the list endpoint may filter and render without reading every entry file; the fields the storage layer relies on are coerced to known types.

array
readIndex()

Read the entry index, rebuilding it when it is missing or corrupt.

array
rebuildIndexFromFiles()

Rebuild the index from the per-entry files.

array
metaFromFiles()

Scan the per-entry files and build the index map straight from their __meta.

void
mutateIndex(callable $mutator)

Apply the given change to the index while holding its exclusive lock.

void
deleteEntries(array $ids)

Delete entry files and remove them from the index in a single rewrite.

array|null
readMeta(string $file)

Read the metadata from the given entry file.

int|null
readLastPrunedAt()

Read the time of the last prune.

void
writeLastPrunedAt(int $timestamp)

Record the time of the last prune.

array|null
readJsonFile(string $file)

Read and decode the given JSON file.

string|null
readLockedTextFile(string $file)

Read the given file under a shared lock.

iterable
jsonFiles()

Get the paths of the per-entry JSON files.

Details

at line 23
__construct(string $path, int $autoPruneHours = 24, Filesystem $files = new Filesystem())

Create a new entries repository instance.

Parameters

string $path
int $autoPruneHours
Filesystem $files

at line 35
void save(string $id, array $data)

Save the given entry payload.

Parameters

string $id
array $data

Return Value

void

at line 62
array|null get(string $id)

Get the payload of the given entry.

Parameters

string $id

Return Value

array|null

at line 84
array all()

All recorded entry metadata, newest first.

Return Value

array

at line 95
void prune(int $hours)

Delete the entries recorded more than the given number of hours ago.

Parameters

int $hours

Return Value

void

at line 116
void enforceTabLimit(string|null $tabUuid, int $limit)

Delete all but the given number of newest entries for the tab. Entries recorded without a tab, such as initial page loads and requests made without the extension, are limited as one group.

Parameters

string|null $tabUuid
int $limit

Return Value

void

at line 136
void pruneIfDue()

Prune expired entries when the prune interval has elapsed.

Return Value

void

at line 161
protected void ensureDirectory()

Ensure the storage directory and its .gitignore exist.

Return Value

void

at line 175
protected string filePath(string $id)

Get the file path of the given entry.

Parameters

string $id

Return Value

string

at line 183
protected bool isValidEntryId(string $id)

Determine if the given entry id is valid.

Parameters

string $id

Return Value

bool

at line 191
protected string indexPath()

Get the path of the index file.

Return Value

string

at line 199
protected string lastPrunePath()

Get the path of the file recording the last prune time.

Return Value

string

at line 212
protected array normalizeIndexMeta(array $meta)

Normalize an entry's __meta for storage in the index. The full meta is kept so the list endpoint may filter and render without reading every entry file; the fields the storage layer relies on are coerced to known types.

Parameters

array $meta

Return Value

array

at line 226
protected array readIndex()

Read the entry index, rebuilding it when it is missing or corrupt.

Return Value

array

at line 251
protected array rebuildIndexFromFiles()

Rebuild the index from the per-entry files.

Return Value

array

at line 269
protected array metaFromFiles()

Scan the per-entry files and build the index map straight from their __meta.

Return Value

array

at line 284
protected void mutateIndex(callable $mutator)

Apply the given change to the index while holding its exclusive lock.

Parameters

callable $mutator

Return Value

void

at line 324
protected void deleteEntries(array $ids)

Delete entry files and remove them from the index in a single rewrite.

Parameters

array $ids

Return Value

void

at line 350
protected array|null readMeta(string $file)

Read the metadata from the given entry file.

Parameters

string $file

Return Value

array|null

at line 364
protected int|null readLastPrunedAt()

Read the time of the last prune.

Return Value

int|null

at line 378
protected void writeLastPrunedAt(int $timestamp)

Record the time of the last prune.

Parameters

int $timestamp

Return Value

void

at line 388
protected array|null readJsonFile(string $file)

Read and decode the given JSON file.

Parameters

string $file

Return Value

array|null

at line 404
protected string|null readLockedTextFile(string $file)

Read the given file under a shared lock.

Parameters

string $file

Return Value

string|null

at line 427
protected iterable jsonFiles()

Get the paths of the per-entry JSON files.

Return Value

iterable