This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DatabaseOwnerFetcher to query for current owner information
Progress on NuGet/NuGetGallery#6475
- Loading branch information
1 parent
1b19717
commit d8b9fbd
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/NuGet.Services.AzureSearch/Owners2AzureSearch/DatabaseOwnerFetcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Logging; | ||
using NuGet.Jobs; | ||
using NuGet.Jobs.Configuration; | ||
|
||
namespace NuGet.Services.AzureSearch.Owners2AzureSearch | ||
{ | ||
public class DatabaseOwnerFetcher : IDatabaseOwnerFetcher | ||
{ | ||
private readonly ISqlConnectionFactory<GalleryDbConfiguration> _connectionFactory; | ||
private readonly ILogger<DatabaseOwnerFetcher> _logger; | ||
|
||
private const string Sql = @" | ||
SELECT | ||
pr.Id, | ||
u.Username | ||
FROM PackageRegistrations pr (NOLOCK) | ||
INNER JOIN PackageRegistrationOwners pro (NOLOCK) ON pro.PackageRegistrationKey = pr.[Key] | ||
INNER JOIN Users u (NOLOCK) ON pro.UserKey = u.[Key] | ||
"; | ||
|
||
public DatabaseOwnerFetcher( | ||
ISqlConnectionFactory<GalleryDbConfiguration> connectionFactory, | ||
ILogger<DatabaseOwnerFetcher> logger) | ||
{ | ||
_connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); | ||
_logger = logger; | ||
} | ||
|
||
public async Task<SortedDictionary<string, SortedSet<string>>> GetPackageIdToOwnersAsync() | ||
{ | ||
using (var connection = await _connectionFactory.OpenAsync()) | ||
using (var command = connection.CreateCommand()) | ||
{ | ||
command.CommandText = Sql; | ||
|
||
using (var reader = await command.ExecuteReaderAsync()) | ||
{ | ||
var builder = new PackageIdToOwnersBuilder(_logger); | ||
while (await reader.ReadAsync()) | ||
{ | ||
var id = reader.GetString(0); | ||
var username = reader.GetString(1); | ||
|
||
builder.Add(id, username); | ||
} | ||
|
||
return builder.GetResult(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
13 changes: 13 additions & 0 deletions
13
src/NuGet.Services.AzureSearch/Owners2AzureSearch/IDatabaseOwnerFetcher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuGet.Services.AzureSearch.Owners2AzureSearch | ||
{ | ||
public interface IDatabaseOwnerFetcher | ||
{ | ||
Task<SortedDictionary<string, SortedSet<string>>> GetPackageIdToOwnersAsync(); | ||
} | ||
} |