Skip to content

Commit

Permalink
Theme Errors: fetch only the theme_errors field of the site object (#…
Browse files Browse the repository at this point in the history
…94425)

* Theme Errors: fetch only the theme_errors field of the site object

* Rename and clarify the fetching helper
  • Loading branch information
jsnajdr authored Sep 12, 2024
1 parent 217d4a9 commit 8acdcd9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions client/my-sites/themes/theme-errors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@ import wpcom from 'calypso/lib/wp';
* We make a separate request rather than using getSite here to
* avoid querying the WP.com cache of a site, which returns theme
* errors for the multisite (caused by its 'force=wpcom' param).
* Also, `theme_errors` is an expensive field that is not normally
* fetched by the common `QuerySite` or `QuerySites` helpers.
*/
async function querySiteDataWithoutForceWpcom( siteId ) {
return await wpcom.req.get( {
function fetchSiteThemeErrorsWithoutForceWpcom( siteId ) {
return wpcom.req.get( {
path: '/sites/' + encodeURIComponent( siteId ),
apiVersion: '1.1',
query: {
fields: 'ID,options',
options: 'theme_errors',
},
} );
}

Expand All @@ -20,13 +26,10 @@ const ThemeErrors = ( { siteId } ) => {
const [ themeErrors, setThemeErrors ] = useState( [] );

useEffect( () => {
const fetchData = async () => {
const siteData = await querySiteDataWithoutForceWpcom( siteId );
fetchSiteThemeErrorsWithoutForceWpcom( siteId ).then( ( siteData ) => {
const errors = siteData?.options?.theme_errors;
setThemeErrors( errors || [] );
};

fetchData();
} );
}, [ siteId ] );

const dismissNotice = ( themeName, errorIndex ) => {
Expand Down

0 comments on commit 8acdcd9

Please sign in to comment.