admin管理员组

文章数量:1125976

the problem is i have to long delay between FE and BE, on the code you can see console.time: console.time('frontEnd archive') === 20000ms and console.time('archive back'); === 40ms.

I have the function on the FE side:

const { electron, RecipeService, MachineService, dialog } = window;

const handleArchiveRecipe = useCallback(async () => {
    try {
      if (selectedRecipe) {
        console.time('frontEnd archive');
        await RecipeService.archiveOne(selectedRecipe._id);
        console.timeEnd('frontEnd archive');
        resetSelect();
        getRecipesFunc().catch(console.error);
      }
    } catch (err) {
      const typedError = err as { message: string };
      console.error(typedError);
      ShowNotification(typedError.message);
    }
  }, [selectedRecipe]);

BE side:

contextBridge.exposeInMainWorld('RecipeService', RecipeService);

export const RecipeService: IRecipeService = {
  archiveOne: async (id: string) => Service.archiveOne(id),
}
class Service {
  static async archiveOne(id: string) {
    console.time('archive back');
    const data = await ipcRenderer.invoke('findById', id, undefined);
    if (data.recipe) {
      const recipe = new Recipe();
      recipe.initPouchRecipe(data.recipe.versions, data.recipe.metadata);
      recipe.versions.forEach((v) => {
        recipe.currentVersionArchivation(v, true, getUserName());
      });
      const res = ipcRenderer.invoke('updateOne', data._id, data._rev, { recipe });
      console.timeEnd('archive back');
      return res;
    }
    throw new Error("Couldn't find the recipe");
  }
}

i have to long delay between FE and BE. I don't know how to fix it, please help me.

I try to reinstall the deps. Also on this project i am working with another developer and we both use windows and he doens't have this problem

本文标签: reactjselectron contextBridge works too slowlyStack Overflow