mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-02 08:58:32 +00:00
refactor: enhance gRPC methods loading with cache indication (#7022)
* refactor: enhance gRPC methods loading with cache indication - Updated `loadMethodsFromReflection` and `loadMethodsFromProtoFile` to return a `fromCache` flag indicating whether methods were loaded from cache. - Adjusted success toast messages to only display when methods are not loaded from cache, improving user feedback on data retrieval. * empty commit * empty
This commit is contained in:
@@ -118,7 +118,7 @@ const GrpcQueryUrl = ({ item, collection, handleRun }) => {
|
||||
};
|
||||
|
||||
const handleReflection = async (url, isManualRefresh = false) => {
|
||||
const { methods, error } = await reflectionManagement.loadMethodsFromReflection(url, isManualRefresh);
|
||||
const { methods, error, fromCache } = await reflectionManagement.loadMethodsFromReflection(url, isManualRefresh);
|
||||
|
||||
if (error) {
|
||||
toast.error(`Failed to load gRPC methods: ${error.message || 'Unknown error'}`);
|
||||
@@ -139,7 +139,7 @@ const GrpcQueryUrl = ({ item, collection, handleRun }) => {
|
||||
}));
|
||||
}
|
||||
|
||||
if (methods && methods.length > 0) {
|
||||
if (!fromCache && methods && methods.length > 0) {
|
||||
toast.success(`Loaded ${methods.length} gRPC methods from reflection`);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ const GrpcQueryUrl = ({ item, collection, handleRun }) => {
|
||||
};
|
||||
|
||||
const handleProtoFileLoad = async (filePath, isManualRefresh = false) => {
|
||||
const { methods, error } = await protoFileManagement.loadMethodsFromProtoFile(filePath, isManualRefresh);
|
||||
const { methods, error, fromCache } = await protoFileManagement.loadMethodsFromProtoFile(filePath, isManualRefresh);
|
||||
|
||||
if (error) {
|
||||
console.error('Failed to load gRPC methods:', error);
|
||||
@@ -174,7 +174,9 @@ const GrpcQueryUrl = ({ item, collection, handleRun }) => {
|
||||
setGrpcMethods(methods);
|
||||
setIsReflectionMode(false);
|
||||
|
||||
toast.success(`Loaded ${methods.length} gRPC methods from proto file`);
|
||||
if (!fromCache) {
|
||||
toast.success(`Loaded ${methods.length} gRPC methods from proto file`);
|
||||
}
|
||||
|
||||
if (methods && methods.length > 0) {
|
||||
const haveSelectedMethod = selectedGrpcMethod && methods.some((method) => method.path === selectedGrpcMethod.path);
|
||||
|
||||
@@ -50,7 +50,7 @@ export default function useProtoFileManagement(collection) {
|
||||
|
||||
const cachedMethods = protofileCache[absolutePath];
|
||||
if (cachedMethods && !isLoadingMethods && !isManualRefresh) {
|
||||
return { methods: cachedMethods, error: null };
|
||||
return { methods: cachedMethods, error: null, fromCache: true };
|
||||
}
|
||||
|
||||
setIsLoadingMethods(true);
|
||||
@@ -67,7 +67,7 @@ export default function useProtoFileManagement(collection) {
|
||||
[absolutePath]: methods
|
||||
}));
|
||||
|
||||
return { methods, error: null };
|
||||
return { methods, error: null, fromCache: false };
|
||||
} catch (err) {
|
||||
console.error('Error loading gRPC methods:', err);
|
||||
return { methods: [], error: err };
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function useReflectionManagement(item, collectionUid) {
|
||||
|
||||
const cachedMethods = reflectionCache[url];
|
||||
if (!isManualRefresh && cachedMethods && !isLoadingMethods) {
|
||||
return { methods: cachedMethods, error: null };
|
||||
return { methods: cachedMethods, error: null, fromCache: true };
|
||||
}
|
||||
|
||||
setIsLoadingMethods(true);
|
||||
@@ -44,7 +44,7 @@ export default function useReflectionManagement(item, collectionUid) {
|
||||
[url]: methods
|
||||
}));
|
||||
|
||||
return { methods, error: null };
|
||||
return { methods, error: null, fromCache: false };
|
||||
} catch (error) {
|
||||
console.error('Error loading gRPC methods:', error);
|
||||
return { methods: [], error };
|
||||
|
||||
Reference in New Issue
Block a user