Skip to content

Commit 2fdec88

Browse files
authored
Avoid calling CreateIfNotExists for Feature Flags (#10258)
1 parent 7e57816 commit 2fdec88

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

src/NuGet.Jobs.Common/JsonConfigurationJob.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -205,7 +205,8 @@ public static void ConfigureFeatureFlagAutofacServices(ContainerBuilder containe
205205
.Register(c => new CloudBlobCoreFileStorageService(
206206
c.ResolveKeyed<ICloudBlobClient>(FeatureFlagBindingKey),
207207
c.Resolve<IDiagnosticsService>(),
208-
c.Resolve<ICloudBlobContainerInformationProvider>()))
208+
c.Resolve<ICloudBlobContainerInformationProvider>(),
209+
initializeContainer: false))
209210
.Keyed<ICoreFileStorageService>(FeatureFlagBindingKey);
210211

211212
containerBuilder

src/NuGetGallery.Core/Services/CloudBlobCoreFileStorageService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ public class CloudBlobCoreFileStorageService : ICoreFileStorageService
3030
protected readonly IDiagnosticsSource _trace;
3131
protected readonly ICloudBlobContainerInformationProvider _cloudBlobFolderInformationProvider;
3232
protected readonly ConcurrentDictionary<string, ICloudBlobContainer> _containers = new ConcurrentDictionary<string, ICloudBlobContainer>();
33+
protected readonly bool _initializeContainer;
3334

3435
public CloudBlobCoreFileStorageService(
3536
ICloudBlobClient client,
3637
IDiagnosticsService diagnosticsService,
37-
ICloudBlobContainerInformationProvider cloudBlobFolderInformationProvider)
38+
ICloudBlobContainerInformationProvider cloudBlobFolderInformationProvider,
39+
bool initializeContainer = true)
3840
{
3941
_client = client ?? throw new ArgumentNullException(nameof(client));
4042
_trace = diagnosticsService?.SafeGetSource(nameof(CloudBlobCoreFileStorageService)) ?? throw new ArgumentNullException(nameof(diagnosticsService));
4143
_cloudBlobFolderInformationProvider = cloudBlobFolderInformationProvider ?? throw new ArgumentNullException(nameof(cloudBlobFolderInformationProvider));
44+
_initializeContainer = initializeContainer;
4245
}
4346

4447
public async Task DeleteFileAsync(string folderName, string fileName)
@@ -598,7 +601,11 @@ private string GetCacheControl(string folderName)
598601
private async Task<ICloudBlobContainer> PrepareContainer(string folderName, bool isPublic)
599602
{
600603
var container = _client.GetContainerReference(folderName);
601-
await container.CreateIfNotExistAsync(isPublic);
604+
605+
if (_initializeContainer)
606+
{
607+
await container.CreateIfNotExistAsync(isPublic);
608+
}
602609

603610
return container;
604611
}

0 commit comments

Comments
 (0)