Skip to content

Commit 12e6f84

Browse files
committed
perf(connection): speed up initial cluster connection
- Remove unnecessary WaitUntilReadyAsync call (SDK handles readiness internally) - Remove redundant GetAllBucketsAsync call for service detection - Reduce operation timeouts from 30s to 10s - Initialize service flags with sensible defaults Connection time reduced from ~20s to ~3s.
1 parent c8c75cd commit 12e6f84

File tree

1 file changed

+6
-43
lines changed

1 file changed

+6
-43
lines changed

src/CodingWithCalvin.CouchbaseExplorer/Services/CouchbaseService.cs

Lines changed: 6 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,15 @@ namespace CodingWithCalvin.CouchbaseExplorer.Services
1111
public class ClusterConnection : IDisposable
1212
{
1313
public ICluster Cluster { get; }
14-
public bool HasQueryService { get; private set; }
15-
public bool HasKvService { get; private set; }
16-
public List<string> AvailableServices { get; private set; } = new List<string>();
14+
public bool HasQueryService { get; private set; } = true;
15+
public bool HasKvService { get; private set; } = true;
16+
public List<string> AvailableServices { get; private set; } = new List<string> { "KV", "Query" };
1717

1818
public ClusterConnection(ICluster cluster)
1919
{
2020
Cluster = cluster;
2121
}
2222

23-
public async Task DetectServicesAsync()
24-
{
25-
try
26-
{
27-
await Cluster.WaitUntilReadyAsync(TimeSpan.FromSeconds(10));
28-
29-
// Try to detect services by attempting operations
30-
HasKvService = true; // KV is always available if connected
31-
32-
// Check for query service by trying to get buckets (uses management API)
33-
try
34-
{
35-
await Cluster.Buckets.GetAllBucketsAsync();
36-
HasQueryService = true;
37-
AvailableServices.Add("Query");
38-
}
39-
catch
40-
{
41-
HasQueryService = false;
42-
}
43-
44-
AvailableServices.Add("KV");
45-
}
46-
catch (Exception)
47-
{
48-
// Service detection failed, assume basic services
49-
HasKvService = true;
50-
AvailableServices.Add("KV");
51-
}
52-
}
53-
5423
public void Dispose()
5524
{
5625
Cluster?.Dispose();
@@ -95,9 +64,9 @@ public static async Task<ClusterConnection> ConnectAsync(string connectionId, st
9564
{
9665
UserName = username,
9766
Password = password,
98-
KvTimeout = TimeSpan.FromSeconds(30),
99-
ManagementTimeout = TimeSpan.FromSeconds(30),
100-
QueryTimeout = TimeSpan.FromSeconds(30)
67+
KvTimeout = TimeSpan.FromSeconds(10),
68+
ManagementTimeout = TimeSpan.FromSeconds(10),
69+
QueryTimeout = TimeSpan.FromSeconds(10)
10170
};
10271

10372
// Check if this is a Capella connection
@@ -131,12 +100,6 @@ public static async Task<ClusterConnection> ConnectAsync(string connectionId, st
131100
}).ConfigureAwait(true);
132101

133102
var connection = new ClusterConnection(cluster);
134-
135-
await Task.Run(async () =>
136-
{
137-
await connection.DetectServicesAsync();
138-
}).ConfigureAwait(true);
139-
140103
_connections[connectionId] = connection;
141104
return connection;
142105
}

0 commit comments

Comments
 (0)