Skip to content

Commit f577a05

Browse files
authored
Merge pull request #1316 from iceljc/master
Disable cache in debug
2 parents 00c85b4 + d1afd4c commit f577a05

File tree

5 files changed

+31
-32
lines changed

5 files changed

+31
-32
lines changed

src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.KnowledgeBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ public async Task<IEnumerable<VectorCollectionConfig>> GetKnowledgeCollectionCon
111111
return configs;
112112
}
113113

114+
#if !DEBUG
114115
[SharpCache(10)]
116+
#endif
115117
public async Task<VectorCollectionConfig> GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider)
116118
{
117119
var configs = await GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter
@@ -121,7 +123,7 @@ public async Task<VectorCollectionConfig> GetKnowledgeCollectionConfig(string co
121123
});
122124
return configs?.FirstOrDefault();
123125
}
124-
#endregion
126+
#endregion
125127

126128

127129
#region Documents

src/Plugins/BotSharp.Plugin.Membase/GraphDb/MembaseGraphDb.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,6 @@ public MembaseGraphDb(
2424

2525
private const int RetryCount = 3;
2626

27-
private AsyncPolicy BuildRetryPolicy()
28-
{
29-
var settings = _services.GetRequiredService<MembaseSettings>();
30-
var timeoutSeconds = (double)settings.TimeoutSecond / RetryCount;
31-
32-
var timeoutPolicy = Policy.TimeoutAsync(TimeSpan.FromSeconds(timeoutSeconds));
33-
34-
var retryPolicy = Policy
35-
.Handle<HttpRequestException>()
36-
.Or<TaskCanceledException>()
37-
.Or<TimeoutRejectedException>()
38-
.Or<ApiException>(ex => ex.StatusCode == HttpStatusCode.ServiceUnavailable)
39-
.WaitAndRetryAsync(
40-
retryCount: RetryCount,
41-
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
42-
onRetry: (ex, timespan, retryAttempt, _) =>
43-
{
44-
_logger.LogWarning(ex,
45-
"CypherQueryAsync retry {RetryAttempt}/{MaxRetries} after {Delay}s. Exception: {Message}",
46-
retryAttempt, RetryCount, timespan.TotalSeconds, ex.Message);
47-
});
48-
49-
return Policy.WrapAsync(retryPolicy, timeoutPolicy);
50-
}
51-
5227
public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryExecuteOptions? options = null)
5328
{
5429
if (string.IsNullOrEmpty(options?.GraphId))
@@ -87,4 +62,30 @@ public async Task<GraphQueryResult> ExecuteQueryAsync(string query, GraphQueryEx
8762
throw;
8863
}
8964
}
65+
66+
67+
private AsyncPolicy BuildRetryPolicy()
68+
{
69+
var settings = _services.GetRequiredService<MembaseSettings>();
70+
var timeoutSeconds = (double)settings.TimeoutSecond / RetryCount;
71+
72+
var timeoutPolicy = Policy.TimeoutAsync(TimeSpan.FromSeconds(timeoutSeconds));
73+
74+
var retryPolicy = Policy
75+
.Handle<HttpRequestException>()
76+
.Or<TaskCanceledException>()
77+
.Or<TimeoutRejectedException>()
78+
.Or<ApiException>(ex => ex.StatusCode == HttpStatusCode.ServiceUnavailable)
79+
.WaitAndRetryAsync(
80+
retryCount: RetryCount,
81+
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
82+
onRetry: (ex, timespan, retryAttempt, _) =>
83+
{
84+
_logger.LogWarning(ex,
85+
"CypherQueryAsync retry {RetryAttempt}/{MaxRetries} after {Delay}s. Exception: {Message}",
86+
retryAttempt, RetryCount, timespan.TotalSeconds, ex.Message);
87+
});
88+
89+
return Policy.WrapAsync(retryPolicy, timeoutPolicy);
90+
}
9091
}

src/Plugins/BotSharp.Plugin.Membase/Services/DemoRuleGraph.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
using BotSharp.Abstraction.Graph;
2-
using BotSharp.Abstraction.Graph.Models;
31
using BotSharp.Abstraction.Rules;
42
using BotSharp.Abstraction.Rules.Models;
53
using BotSharp.Abstraction.Rules.Options;
64
using BotSharp.Abstraction.Utilities;
7-
using Microsoft.Extensions.Logging;
8-
using System.Text.Json;
95

106
namespace BotSharp.Plugin.Membase.Services;
117

src/Plugins/BotSharp.Plugin.Membase/Settings/MembaseSettings.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using BotSharp.Abstraction.Graph.Models;
2-
31
namespace BotSharp.Plugin.Membase.Settings;
42

53
public class MembaseSettings

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.KnowledgeBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ public async Task<IEnumerable<VectorCollectionConfig>> GetKnowledgeCollectionCon
116116
});
117117
}
118118

119+
#if !DEBUG
119120
[SharpCache(10)]
121+
#endif
120122
public async Task<VectorCollectionConfig> GetKnowledgeCollectionConfig(string collectionName, string vectorStroageProvider)
121123
{
122124
var configs = await GetKnowledgeCollectionConfigs(new VectorCollectionConfigFilter

0 commit comments

Comments
 (0)