Skip to content

Commit 8a9a1cd

Browse files
authored
Refactor ExpandedPackageRepository out of ServerPackageRepository (#26)
Split a lot of logic out of ServerPackageRepository into another class so concerns are easier to understand Add testing around package removal (both unlisting on and off). Clean up implementations so we don't need to as cast IServerPackage to ServerPackage (strengthening the IServerPackage API) Add missing test for NuGet/NuGetGallery#3277 Remove dead code. Clean up some inconsistently styled code
1 parent c78bd4e commit 8a9a1cd

24 files changed

Lines changed: 1089 additions & 756 deletions

src/NuGet.Server.Core/DataServices/ODataPackage.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
34
using System;
4-
using System.Data.Services.Common;
55

66
namespace NuGet.Server.Core.DataServices
77
{
8-
[DataServiceKey("Id", "Version")]
9-
[EntityPropertyMapping("Id", SyndicationItemProperty.Title, SyndicationTextContentKind.Plaintext, keepInContent: false)]
10-
[EntityPropertyMapping("Authors", SyndicationItemProperty.AuthorName, SyndicationTextContentKind.Plaintext, keepInContent: false)]
11-
[EntityPropertyMapping("LastUpdated", SyndicationItemProperty.Updated, SyndicationTextContentKind.Plaintext, keepInContent: false)]
12-
[EntityPropertyMapping("Summary", SyndicationItemProperty.Summary, SyndicationTextContentKind.Plaintext, keepInContent: false)]
13-
[HasStream]
148
public class ODataPackage
159
{
1610
public string Id { get; set; }

src/NuGet.Server.Core/DataServices/PackageContext.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Collections.Generic;
5+
6+
namespace NuGet.Server.Core.Infrastructure
7+
{
8+
/// <summary>
9+
/// This interface provides a relatively high performance view of the packages available on the server. The default
10+
/// implementation of this interface stores package metadata in memory and persists it to disk as a JSON file, which
11+
/// is much faster to read than opening up all of the .nupkg each time their metadata is needed.
12+
/// </summary>
13+
public interface IServerPackageCache
14+
{
15+
bool IsEmpty();
16+
17+
IEnumerable<ServerPackage> GetAll();
18+
19+
void Add(ServerPackage entity);
20+
21+
void AddRange(IEnumerable<ServerPackage> entities);
22+
23+
void Remove(string id, SemanticVersion version, bool enableDelisting);
24+
25+
void Persist();
26+
27+
void PersistIfDirty();
28+
29+
void Clear();
30+
}
31+
}

src/NuGet.Server.Core/Infrastructure/IServerPackageRepository.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System.Collections.Generic;
55
using System.Linq;
6-
using System.Runtime.Versioning;
76

87
namespace NuGet.Server.Core.Infrastructure
98
{
@@ -15,13 +14,6 @@ public interface IServerPackageRepository
1514

1615
IQueryable<IServerPackage> GetPackages();
1716

18-
IEnumerable<IServerPackage> GetUpdates(
19-
IEnumerable<IPackageName> packages,
20-
bool includePrerelease,
21-
bool includeAllVersions,
22-
IEnumerable<FrameworkName> targetFrameworks,
23-
IEnumerable<IVersionSpec> versionConstraints);
24-
2517
IQueryable<IServerPackage> Search(
2618
string searchTerm,
2719
IEnumerable<string> targetFrameworks,
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
2-
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
34
using System.Collections.Generic;
4-
using System.Linq;
55

66
namespace NuGet.Server.Core.Infrastructure
77
{
8+
/// <summary>
9+
/// This interface provides a way to add and remove packages from disk. This store is meant to be the definitive
10+
/// collection of packages available. If the metadata cache (see <see cref="IServerPackageCache"/>) is out of date
11+
/// or corrupted, all metadata should be able to be rebuilt by enumerating a reading packages in this store.
12+
/// </summary>
813
public interface IServerPackageStore
914
{
10-
bool HasPackages();
11-
IQueryable<ServerPackage> GetAll();
12-
void Store(ServerPackage entity);
13-
void StoreRange(IEnumerable<ServerPackage> entities);
14-
void Remove(ServerPackage entity);
15-
void Remove(string id, SemanticVersion version);
16-
void Persist();
17-
void PersistIfDirty();
18-
void Clear();
15+
ServerPackage Add(IPackage package, bool enableDelisting);
16+
17+
bool Exists(string id, SemanticVersion version);
18+
19+
HashSet<ServerPackage> GetAll(bool enableDelisting);
20+
21+
void Remove(string id, SemanticVersion version, bool enableDelisting);
1922
}
2023
}

src/NuGet.Server.Core/Infrastructure/ServerPackage.cs

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Globalization;
7-
using System.IO;
87
using System.Linq;
98
using System.Runtime.Versioning;
109
using Newtonsoft.Json;
@@ -19,75 +18,8 @@ public ServerPackage()
1918
}
2019

2120
public ServerPackage(
22-
string id,
23-
SemanticVersion version,
24-
string title,
25-
IEnumerable<string> authors,
26-
IEnumerable<string> owners,
27-
Uri iconUrl,
28-
Uri licenseUrl,
29-
Uri projectUrl,
30-
bool requireLicenseAcceptance,
31-
bool developmentDependency,
32-
string description,
33-
string summary,
34-
string releaseNotes,
35-
string language,
36-
string tags,
37-
string copyright,
38-
string dependencies,
39-
Version minClientVersion,
40-
Uri reportAbuseUrl,
41-
int downloadCount,
42-
string supportedFrameworks,
43-
bool isAbsoluteLatestVersion,
44-
bool isLatestVersion,
45-
bool listed,
46-
DateTimeOffset? published,
47-
long packageSize,
48-
string packageHash,
49-
string packageHashAlgorithm,
50-
DateTimeOffset lastUpdated,
51-
DateTimeOffset created,
52-
string fullPath)
53-
{
54-
Id = id;
55-
Version = version;
56-
Title = title;
57-
Authors = authors;
58-
Owners = owners;
59-
IconUrl = iconUrl;
60-
LicenseUrl = licenseUrl;
61-
ProjectUrl = projectUrl;
62-
RequireLicenseAcceptance = requireLicenseAcceptance;
63-
DevelopmentDependency = developmentDependency;
64-
Description = description;
65-
Summary = summary;
66-
ReleaseNotes = releaseNotes;
67-
Language = language;
68-
Tags = tags;
69-
Copyright = copyright;
70-
Dependencies = dependencies;
71-
MinClientVersion = minClientVersion;
72-
ReportAbuseUrl = reportAbuseUrl;
73-
DownloadCount = downloadCount;
74-
SupportedFrameworks = supportedFrameworks;
75-
IsAbsoluteLatestVersion = isAbsoluteLatestVersion;
76-
IsLatestVersion = isLatestVersion;
77-
Listed = listed;
78-
PackageSize = packageSize;
79-
PackageHash = packageHash;
80-
PackageHashAlgorithm = packageHashAlgorithm;
81-
LastUpdated = lastUpdated;
82-
Created = created;
83-
FullPath = fullPath;
84-
85-
// Preload collections
86-
DependencySets.Any();
87-
SupportedFrameworks.Any();
88-
}
89-
90-
public ServerPackage(IPackage package, PackageDerivedData packageDerivedData)
21+
IPackage package,
22+
PackageDerivedData packageDerivedData)
9123
{
9224
Id = package.Id;
9325
Version = package.Version;

0 commit comments

Comments
 (0)