mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
Removed local storage caching
refs https://github.com/TryGhost/Team/issues/1665 - This is a premature optimization that's causing loads of roadblocks while everyone is cracking on the feature (the data format changes, etc.) - Once we are set on the format and need a performance boost we should design a suitable caching mechanism (the current one does not take resource updates into account, so can cause stale content)
This commit is contained in:
parent
9460875638
commit
b6ecad0488
@ -1,10 +1,9 @@
|
||||
import elasticlunr from 'elasticlunr';
|
||||
|
||||
export default class SearchIndex {
|
||||
constructor({apiUrl, apiKey, storage = localStorage}) {
|
||||
constructor({apiUrl, apiKey}) {
|
||||
this.apiUrl = apiUrl;
|
||||
this.apiKey = apiKey;
|
||||
this.storage = storage;
|
||||
|
||||
this.postsIndex = null;
|
||||
this.authorsIndex = null;
|
||||
@ -22,9 +21,6 @@ export default class SearchIndex {
|
||||
slug: post.slug
|
||||
});
|
||||
});
|
||||
|
||||
this.storage.setItem('ease_search_index', JSON.stringify(this.postsIndex));
|
||||
this.storage.setItem('ease_search_last', data.posts[0].updated_at);
|
||||
}
|
||||
|
||||
#updateAuthorsIndex(data) {
|
||||
@ -53,12 +49,6 @@ export default class SearchIndex {
|
||||
const authorsAPIUrl = `${this.apiUrl}/authors/?key=${this.apiKey}&limit=all&fields=id,slug,name,url,profile_image`;
|
||||
const tagsAPIUrl = `${this.apiUrl}/tags/?key=${this.apiKey}&limit=all&fields=id,slug,name,url`;
|
||||
|
||||
const indexDump = JSON.parse(this.storage.getItem('ease_search_index'));
|
||||
|
||||
this.storage.removeItem('ease_index');
|
||||
this.storage.removeItem('ease_last');
|
||||
|
||||
if (!indexDump) {
|
||||
const postsResponse = await fetch(postsAPIUrl);
|
||||
const posts = await postsResponse.json();
|
||||
|
||||
@ -95,18 +85,6 @@ export default class SearchIndex {
|
||||
if (tags.tags.length > 0) {
|
||||
this.#updateTagsIndex(tags);
|
||||
}
|
||||
} else {
|
||||
this.postsIndex = elasticlunr.Index.load(indexDump);
|
||||
|
||||
return fetch(`${postsAPIUrl}&filter=updated_at:>'${this.storage.getItem('ease_search_last').replace(/\..*/, '').replace(/T/, ' ')}'`
|
||||
)
|
||||
.then(response => response.json())
|
||||
.then((data) => {
|
||||
if (data.posts.length > 0) {
|
||||
this.#updatePostIndex(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
search(value) {
|
||||
|
Loading…
Reference in New Issue
Block a user