diff --git a/src/isn/isn.csproj b/src/isn/isn.csproj
index b5aa589..f150f16 100644
--- a/src/isn/isn.csproj
+++ b/src/isn/isn.csproj
@@ -21,8 +21,6 @@
-
-
\ No newline at end of file
diff --git a/src/isnd/Data/Catalog/RegistrationPage.cs b/src/isnd/Data/Catalog/RegistrationPage.cs
index a12db3d..f1af578 100644
--- a/src/isnd/Data/Catalog/RegistrationPage.cs
+++ b/src/isnd/Data/Catalog/RegistrationPage.cs
@@ -31,10 +31,10 @@ namespace isnd.Data.Catalog
Bid = bid;
Parent = Bid + $"/{pkgid}/index.json";
DlBase = dlBase;
- this.items = new List(items);
+ this.items = new List();
this.Id = Bid + "/" + pkgid + "/index.json";
this.pkgid = pkgid;
- UpdateCompact();
+ AddVersionRange(items);
}
public string GetPackageId()
@@ -42,28 +42,6 @@ namespace isnd.Data.Catalog
return pkgid;
}
- private void UpdateCompact()
- {
- NuGetVersion upper = new NuGetVersion(0,0,0);
-
- // Assert.True(items.All(p=>p.Id == id));
- long commitMax = 0;
- foreach (var p in items)
- {
- if (upper < p.NugetVersion) upper = p.NugetVersion;
- }
- Upper = upper.ToFullString();
- NuGetVersion lower = upper;
- foreach (var p in items)
- {
- if (lower > p.NugetVersion) lower = p.NugetVersion;
- if (p.CommitNId>commitMax) commitMax = p.CommitNId;
- }
- Lower = lower.ToFullString();
- Count = items.Count;
- CommitId = commitMax.ToString();
- }
-
///
/// no The array of registration leaves and their associate metadata
///
@@ -75,9 +53,27 @@ namespace isnd.Data.Catalog
public void AddVersionRange(IEnumerable vitems)
{
if (vitems.Count() == 0) return;
- items.AddRange(vitems);
- UpdateCompact();
+ NuGetVersion upper = null;
+ NuGetVersion lower = null;
+ if (Lower!=null) lower = new NuGetVersion(Lower);
+ if (Upper!=null) upper = new NuGetVersion(Upper);
+
+ // Assert.True(items.All(p=>p.Id == id));
+ long commitMax = 0;
+ foreach (var p in vitems)
+ {
+ if (items.Contains(p))
+ continue;
+ if (upper == null || upper < p.NugetVersion) upper = p.NugetVersion;
+ if (lower == null || lower > p.NugetVersion) lower = p.NugetVersion;
+ if (p.CommitNId> commitMax) commitMax = p.CommitNId;
+ items.Add(p);
+ }
+ Upper = upper.ToFullString();
+ Lower = lower.ToFullString();
+ CommitId = commitMax.ToString();
}
+
///
/// The highest SemVer 2.0.0 version in the page (inclusive)
///
@@ -99,7 +95,7 @@ namespace isnd.Data.Catalog
public string Parent { get; set; }
[JsonProperty("count")]
- public int Count { get; internal set; }
+ public int Count { get => items.Count; }
public string CommitId { get; internal set; }
public DateTime CommitTimeStamp { get; internal set; }
}
diff --git a/src/isnd/Data/Catalog/RegistrationPageIndex.cs b/src/isnd/Data/Catalog/RegistrationPageIndex.cs
index eb4b55a..0ec5527 100644
--- a/src/isnd/Data/Catalog/RegistrationPageIndex.cs
+++ b/src/isnd/Data/Catalog/RegistrationPageIndex.cs
@@ -22,7 +22,6 @@ namespace isnd.Data.Catalog
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable pkgs)
{
-
Items = new List();
long cnid = 0;
var pkgsGroups = pkgs.GroupBy(l => l.Id);
@@ -47,11 +46,10 @@ namespace isnd.Data.Catalog
}
CommitId = cnid.ToString();
Id = bid + $"/{id}/index.json";
- Count = Items.Count;
}
[JsonProperty("count")]
- public int Count { get ; private set; }
+ public int Count { get => Items.Count; }
[JsonProperty("items")]
public List Items { get; set; }
diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs
index cd1ef4f..9d553d5 100644
--- a/src/isnd/Services/PackageManager.cs
+++ b/src/isnd/Services/PackageManager.cs
@@ -44,7 +44,7 @@ namespace isnd.Services
new Resource
{
Id = extUrl + ApiConfig.Publish,
- Type = "PackagePublish/2.0.0", // TODO BASE_API_LEVEL
+ Type = "PackagePublish/2.0.0",
Comment = "Package Publish service"
});
// under dev, only leash in release mode
@@ -72,7 +72,7 @@ namespace isnd.Services
Type = "SearchQueryService/" + BASE_API_LEVEL,
Comment = "Search Query service"
});
- if (unleashClient.IsEnabled("pkg-catalog", false))
+ if (unleashClient.IsEnabled("pkg-catalog", true))
res.Add(
new Resource
{
@@ -81,7 +81,6 @@ namespace isnd.Services
Comment = "Package Catalog Index"
});
- /* FIXME */
res.Add(
new Resource
{
@@ -160,14 +159,14 @@ namespace isnd.Services
.Skip(skip).Take(take).ToArray();
}
-
+
public string CatalogBaseUrl => extUrl;
private IsndSettings isndSettings;
private string extUrl;
- public virtual async TaskGetCatalogIndexAsync()
+ public virtual async Task GetCatalogIndexAsync()
{
return await ÛpdateCatalogForAsync(null);
}
@@ -175,14 +174,12 @@ namespace isnd.Services
public async Task ÛpdateCatalogForAsync(Commit reason = null)
{
int i = 0;
-
+
string baseid = extUrl + ApiConfig.Catalog;
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
- string basepageid = extUrl + ApiConfig.CatalogPage;
RegistrationPageIndex CurrentCatalogIndex = new RegistrationPageIndex();
- List CurrentCatalogPages = new List();
- var scope = dbContext.Commits.OrderBy(c => c.TimeStamp);
+ var scope = await dbContext.Commits.OrderBy(c => c.TimeStamp).ToArrayAsync();
RegistrationPage page = null;
i = isndSettings.CatalogPageLen;
@@ -190,44 +187,25 @@ namespace isnd.Services
{
if (i >= this.isndSettings.CatalogPageLen)
{
- page = new RegistrationPage(basepageid, extUrl)
- {
- CommitId = commit.CommitId,
- CommitTimeStamp = commit.CommitTimeStamp
- };
- CurrentCatalogPages.Add(page);
- var pageRef = new RegistrationPage(page.Id, extUrl)
+ page = new RegistrationPage(bidreg, extUrl)
{
CommitId = commit.CommitId,
CommitTimeStamp = commit.CommitTimeStamp
};
- CurrentCatalogIndex.Items.Add(pageRef);
+ CurrentCatalogIndex.Items.Add(page);
i = 0;
}
- var validPkgs = dbContext.Packages
+ var validPkgs = (await dbContext.Packages
.Include(po => po.Owner)
.Include(pkg => pkg.Versions)
.Include(pkg => pkg.LatestVersion)
- .ToList()
+ .ToArrayAsync())
.GroupBy((q) => q.Id);
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
foreach (var pkgid in validPkgs)
{
- StringBuilder refid = new StringBuilder(bidreg);
- refid.AppendFormat("{0}/",
- pkgid.Key);
- /* var pkgref = new PackageRef
- {
- Version = v.FullString,
- LastCommit = v.LatestCommit,
- CommitId = v.LatestCommit.CommitId,
- CommitTimeStamp = v.LatestCommit.CommitTimeStamp,
- RefId = refid.ToString(),
- Id = v.PackageId,
- RefType = v.LatestCommit.Action == PackageAction.PublishPackage
- ? "nuget:PackageDetails" :
- "nuget:PackageDelete"
- }; */
+ StringBuilder refid = new(bidreg);
+ refid.AppendFormat("{0}/", pkgid.Key);
foreach (var pkgv in pkgid)
page.AddVersionRange(pkgv.Versions);
}
@@ -280,7 +258,7 @@ namespace isnd.Services
);
}
- public IEnumerable GetCatalogLeaf(string pkgId, string semver=null, string pkgType=null)
+ public IEnumerable GetCatalogLeaf(string pkgId, string semver = null, string pkgType = null)
{
return dbContext.PackageVersions
.Include(v => v.Package)
@@ -309,9 +287,9 @@ namespace isnd.Services
.Include(v => v.Package)
.Include(v => v.Package.Owner)
.Include(v => v.LatestCommit)
- .Where(v => v.PackageId.Equals(pkgId, StringComparison.InvariantCultureIgnoreCase) && semver.Equals(v.FullString, StringComparison.InvariantCultureIgnoreCase)
+ .Where(v => v.PackageId == pkgId && semver == v.FullString
&& (pkgType == null || pkgType == v.Type))
- .OrderByDescending(p=> p.CommitNId)
+ .OrderByDescending(p => p.CommitNId)
.Select(p => p.ToLeave(bid, extUrl))
;
}
@@ -327,40 +305,39 @@ namespace isnd.Services
public async Task GetPackageRegistrationIndexAsync(RegistrationPageIndexQuery query)
{
// RegistrationPageIndexAndQuery
- var scope = (await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
- .ToListAsync()) .Where(p => MatchingExact(p, query));
- var total = scope.Count();
- var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray();
+ var scope = await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
+ .Where(p => MatchingExact(p, query)).Skip(query.Skip).Take(query.Take).ToListAsync();
+
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
return
- new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
+ new RegistrationPageIndex(bid, query.Query, extUrl, scope);
}
public async Task SearchPackageAsync(RegistrationPageIndexQuery query)
{
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
-
+
if (query.Query == null) query.Query = "";
var scope = (await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
.ToListAsync())
- .Where(p => Matching(p,query))
+ .Where(p => Matching(p, query))
;
- var total = scope.Count();
- var pkgs = scope.Skip(query.Skip).Take(query.Take);
+ var total = scope.Count();
+ var pkgs = scope.Skip(query.Skip).Take(query.Take);
return
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
}
- private static bool MatchingExact(Package p, RegistrationPageIndexQuery query)
+ private static bool MatchingExact(Package p, RegistrationPageIndexQuery query)
{
return
- p.Id.Equals(query.Query, StringComparison.InvariantCultureIgnoreCase)
+ p.Id == query.Query
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease));
}
private static bool Matching(Package p, RegistrationPageIndexQuery query)
{
- return p.Id.StartsWith(query.Query, StringComparison.InvariantCultureIgnoreCase)
+ return p.Id.StartsWith(query.Query)
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease));
}
}