1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(entries): Entries API fetch improvements. #491

This commit is contained in:
Awilum
2020-12-11 14:56:24 +03:00
parent 7e4c6c23ad
commit 0ac347d211

View File

@@ -118,11 +118,9 @@ class Entries
// 1. Try to get current requested entry from cache
if (flextype('cache')->has($entryCacheID)) {
// Fetch entry from cache
$this->storage['fetch']['data'] = flextype('cache')->get($entryCacheID);
// Apply filter for fetch data
$this->storage['fetch']['data'] = filter($this->storage['fetch']['data'],
// Fetch entry from cache and Apply filter for fetch data
$this->storage['fetch']['data'] = filter(flextype('cache')->get($entryCacheID),
$this->storage['fetch']['options']);
// Run event: onEntriesFetchSingleCacheHasResult
@@ -139,24 +137,24 @@ class Entries
// Try to get requested entry from the filesystem
$entryFileContent = filesystem()->file($entryFile)->get();
if ($entryFileContent === false) {
return arrays();
// Run event: onEntriesFetchSingleNoResult
flextype('emitter')->emit('onEntriesFetchSingleNoResult');
return arrays($this->storage['fetch']['data']);
}
// Decode entry file content
$this->storage['fetch']['data'] = flextype('frontmatter')->decode($entryFileContent);
// Set cache state
$cache = flextype('entries')->storage['fetch']['data']['cache']['enabled'] ??
flextype('registry')->get('flextype.settings.cache.enabled');
// Apply filter for fetch data
$this->storage['fetch']['data'] = filter($this->storage['fetch']['data'],
// Decode entry file content and Apply filter for fetch data
$this->storage['fetch']['data'] = filter(flextype('frontmatter')->decode($entryFileContent),
$this->storage['fetch']['options']);
// Run event: onEntriesFetchSingleHasResult
flextype('emitter')->emit('onEntriesFetchSingleHasResult');
// Set cache state
$cache = flextype('entries')->storage['fetch']['data']['cache']['enabled'] ??
flextype('registry')->get('flextype.settings.cache.enabled');
// Save entry data to cache
if ($cache) {
flextype('cache')->set($entryCacheID, $this->storage['fetch']['data']);