Moved fetching site data to first load of search popup

refs https://github.com/TryGhost/Team/issues/1665

- previously the search was loading site data on load for indexing, which adds unnecessary load if search is not used
- moves data fetch and indexing to when the search popup is opened first time avoiding unnecessary fetch
This commit is contained in:
Rishabh 2022-07-08 10:37:32 +02:00
parent c30cb19650
commit 1e57af8fdd
2 changed files with 22 additions and 7 deletions

View File

@ -15,16 +15,14 @@ export default class App extends React.Component {
this.state = {
searchIndex,
showPopup: false
showPopup: false,
indexStarted: false,
indexComplete: false
};
}
async componentDidMount() {
componentDidMount() {
this.initSetup();
await this.state.searchIndex.init();
this.setState({
indexComplete: true
});
}
componentDidUpdate(_prevProps, _prevState) {
@ -33,6 +31,20 @@ export default class App extends React.Component {
searchValue: ''
});
}
if (this.state.showPopup && !this.state.indexStarted) {
this.setupSearchIndex();
}
}
async setupSearchIndex() {
this.setState({
indexStarted: true
});
await this.state.searchIndex.init();
this.setState({
indexComplete: true
});
}
componentWillUnmount() {

View File

@ -9,7 +9,10 @@ const AppContext = React.createContext({
lastPage: '',
page: '',
pageData: {},
dispatch: (_action, _data) => {}
dispatch: (_action, _data) => {},
searchIndex: null,
indexComplete: false,
searchValue: ''
});
export default AppContext;