EntriesRepository
class EntriesRepository
Constants
| protected INDEX_FILE |
|
| protected LAST_PRUNE_FILE |
|
Methods
Create a new entries repository instance.
Save the given entry payload.
Get the payload of the given entry.
All recorded entry metadata, newest first.
Delete the entries recorded more than the given number of hours ago.
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.
Prune expired entries when the prune interval has elapsed.
Ensure the storage directory and its .gitignore exist.
Get the file path of the given entry.
Determine if the given entry id is valid.
Get the path of the index file.
Get the path of the file recording the last prune time.
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.
Read the entry index, rebuilding it when it is missing or corrupt.
Rebuild the index from the per-entry files.
Scan the per-entry files and build the index map straight from their __meta.
Apply the given change to the index while holding its exclusive lock.
Delete entry files and remove them from the index in a single rewrite.
Read the metadata from the given entry file.
Read the time of the last prune.
Record the time of the last prune.
Read and decode the given JSON file.
Read the given file under a shared lock.
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.
at line 35
void
save(string $id, array $data)
Save the given entry payload.
at line 62
array|null
get(string $id)
Get the payload of the given entry.
at line 84
array
all()
All recorded entry metadata, newest first.
at line 95
void
prune(int $hours)
Delete the entries recorded more than the given number of hours ago.
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.
at line 136
void
pruneIfDue()
Prune expired entries when the prune interval has elapsed.
at line 161
protected void
ensureDirectory()
Ensure the storage directory and its .gitignore exist.
at line 175
protected string
filePath(string $id)
Get the file path of the given entry.
at line 183
protected bool
isValidEntryId(string $id)
Determine if the given entry id is valid.
at line 191
protected string
indexPath()
Get the path of the index file.
at line 199
protected string
lastPrunePath()
Get the path of the file recording the last prune time.
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.
at line 226
protected array
readIndex()
Read the entry index, rebuilding it when it is missing or corrupt.
at line 251
protected array
rebuildIndexFromFiles()
Rebuild the index from the per-entry files.
at line 269
protected array
metaFromFiles()
Scan the per-entry files and build the index map straight from their __meta.
at line 284
protected void
mutateIndex(callable $mutator)
Apply the given change to the index while holding its exclusive lock.
at line 324
protected void
deleteEntries(array $ids)
Delete entry files and remove them from the index in a single rewrite.
at line 350
protected array|null
readMeta(string $file)
Read the metadata from the given entry file.
at line 364
protected int|null
readLastPrunedAt()
Read the time of the last prune.
at line 378
protected void
writeLastPrunedAt(int $timestamp)
Record the time of the last prune.
at line 388
protected array|null
readJsonFile(string $file)
Read and decode the given JSON file.
at line 404
protected string|null
readLockedTextFile(string $file)
Read the given file under a shared lock.
at line 427
protected iterable
jsonFiles()
Get the paths of the per-entry JSON files.