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 (#501)
Progress on NuGet/NuGetGallery#6475
- Loading branch information
1 parent
aa7a233
commit c3c1cfc
Showing
7 changed files
with
96 additions
and
4 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(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
// 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 | ||
{ | ||
/// <summary> | ||
/// Fetches the current owner information from the database. | ||
/// </summary> | ||
public interface IDatabaseOwnerFetcher | ||
{ | ||
/// <summary> | ||
/// Fetch a mapping from package ID to set of owners for each package registration (i.e. package ID) in the | ||
/// gallery database. | ||
/// </summary> | ||
Task<SortedDictionary<string, SortedSet<string>>> GetPackageIdToOwnersAsync(); | ||
} | ||
} |
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
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