a descent catalog index /catalog
This commit is contained in:
parent
4f040be236
commit
ca079e1c47
4 changed files with 50 additions and 81 deletions
|
|
@ -21,8 +21,6 @@
|
||||||
<Reference Include="System.Net.Http" Version="4.0.0" />
|
<Reference Include="System.Net.Http" Version="4.0.0" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10*" />
|
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10*" />
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="../isn.abst/isn.abst.csproj" />
|
<ProjectReference Include="../isn.abst/isn.abst.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
@ -31,10 +31,10 @@ namespace isnd.Data.Catalog
|
||||||
Bid = bid;
|
Bid = bid;
|
||||||
Parent = Bid + $"/{pkgid}/index.json";
|
Parent = Bid + $"/{pkgid}/index.json";
|
||||||
DlBase = dlBase;
|
DlBase = dlBase;
|
||||||
this.items = new List<PackageVersion>(items);
|
this.items = new List<PackageVersion>();
|
||||||
this.Id = Bid + "/" + pkgid + "/index.json";
|
this.Id = Bid + "/" + pkgid + "/index.json";
|
||||||
this.pkgid = pkgid;
|
this.pkgid = pkgid;
|
||||||
UpdateCompact();
|
AddVersionRange(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetPackageId()
|
public string GetPackageId()
|
||||||
|
|
@ -42,28 +42,6 @@ namespace isnd.Data.Catalog
|
||||||
return pkgid;
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// no The array of registration leaves and their associate metadata
|
/// no The array of registration leaves and their associate metadata
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -75,9 +53,27 @@ namespace isnd.Data.Catalog
|
||||||
public void AddVersionRange(IEnumerable<PackageVersion> vitems)
|
public void AddVersionRange(IEnumerable<PackageVersion> vitems)
|
||||||
{
|
{
|
||||||
if (vitems.Count() == 0) return;
|
if (vitems.Count() == 0) return;
|
||||||
items.AddRange(vitems);
|
NuGetVersion upper = null;
|
||||||
UpdateCompact();
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The highest SemVer 2.0.0 version in the page (inclusive)
|
/// The highest SemVer 2.0.0 version in the page (inclusive)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -99,7 +95,7 @@ namespace isnd.Data.Catalog
|
||||||
public string Parent { get; set; }
|
public string Parent { get; set; }
|
||||||
|
|
||||||
[JsonProperty("count")]
|
[JsonProperty("count")]
|
||||||
public int Count { get; internal set; }
|
public int Count { get => items.Count; }
|
||||||
public string CommitId { get; internal set; }
|
public string CommitId { get; internal set; }
|
||||||
public DateTime CommitTimeStamp { get; internal set; }
|
public DateTime CommitTimeStamp { get; internal set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@ namespace isnd.Data.Catalog
|
||||||
|
|
||||||
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable<Package> pkgs)
|
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable<Package> pkgs)
|
||||||
{
|
{
|
||||||
|
|
||||||
Items = new List<RegistrationPage>();
|
Items = new List<RegistrationPage>();
|
||||||
long cnid = 0;
|
long cnid = 0;
|
||||||
var pkgsGroups = pkgs.GroupBy(l => l.Id);
|
var pkgsGroups = pkgs.GroupBy(l => l.Id);
|
||||||
|
|
@ -47,11 +46,10 @@ namespace isnd.Data.Catalog
|
||||||
}
|
}
|
||||||
CommitId = cnid.ToString();
|
CommitId = cnid.ToString();
|
||||||
Id = bid + $"/{id}/index.json";
|
Id = bid + $"/{id}/index.json";
|
||||||
Count = Items.Count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonProperty("count")]
|
[JsonProperty("count")]
|
||||||
public int Count { get ; private set; }
|
public int Count { get => Items.Count; }
|
||||||
|
|
||||||
[JsonProperty("items")]
|
[JsonProperty("items")]
|
||||||
public List<RegistrationPage> Items { get; set; }
|
public List<RegistrationPage> Items { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -44,7 +44,7 @@ namespace isnd.Services
|
||||||
new Resource
|
new Resource
|
||||||
{
|
{
|
||||||
Id = extUrl + ApiConfig.Publish,
|
Id = extUrl + ApiConfig.Publish,
|
||||||
Type = "PackagePublish/2.0.0", // TODO BASE_API_LEVEL
|
Type = "PackagePublish/2.0.0",
|
||||||
Comment = "Package Publish service"
|
Comment = "Package Publish service"
|
||||||
});
|
});
|
||||||
// under dev, only leash in release mode
|
// under dev, only leash in release mode
|
||||||
|
|
@ -72,7 +72,7 @@ namespace isnd.Services
|
||||||
Type = "SearchQueryService/" + BASE_API_LEVEL,
|
Type = "SearchQueryService/" + BASE_API_LEVEL,
|
||||||
Comment = "Search Query service"
|
Comment = "Search Query service"
|
||||||
});
|
});
|
||||||
if (unleashClient.IsEnabled("pkg-catalog", false))
|
if (unleashClient.IsEnabled("pkg-catalog", true))
|
||||||
res.Add(
|
res.Add(
|
||||||
new Resource
|
new Resource
|
||||||
{
|
{
|
||||||
|
|
@ -81,7 +81,6 @@ namespace isnd.Services
|
||||||
Comment = "Package Catalog Index"
|
Comment = "Package Catalog Index"
|
||||||
});
|
});
|
||||||
|
|
||||||
/* FIXME */
|
|
||||||
res.Add(
|
res.Add(
|
||||||
new Resource
|
new Resource
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +166,7 @@ namespace isnd.Services
|
||||||
private IsndSettings isndSettings;
|
private IsndSettings isndSettings;
|
||||||
private string extUrl;
|
private string extUrl;
|
||||||
|
|
||||||
public virtual async Task<RegistrationPageIndex>GetCatalogIndexAsync()
|
public virtual async Task<RegistrationPageIndex> GetCatalogIndexAsync()
|
||||||
{
|
{
|
||||||
return await ÛpdateCatalogForAsync(null);
|
return await ÛpdateCatalogForAsync(null);
|
||||||
}
|
}
|
||||||
|
|
@ -178,11 +177,9 @@ namespace isnd.Services
|
||||||
|
|
||||||
string baseid = extUrl + ApiConfig.Catalog;
|
string baseid = extUrl + ApiConfig.Catalog;
|
||||||
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
||||||
string basepageid = extUrl + ApiConfig.CatalogPage;
|
|
||||||
RegistrationPageIndex CurrentCatalogIndex = new RegistrationPageIndex();
|
RegistrationPageIndex CurrentCatalogIndex = new RegistrationPageIndex();
|
||||||
List<RegistrationPage> CurrentCatalogPages = new List<RegistrationPage>();
|
|
||||||
|
|
||||||
var scope = dbContext.Commits.OrderBy(c => c.TimeStamp);
|
var scope = await dbContext.Commits.OrderBy(c => c.TimeStamp).ToArrayAsync();
|
||||||
|
|
||||||
RegistrationPage page = null;
|
RegistrationPage page = null;
|
||||||
i = isndSettings.CatalogPageLen;
|
i = isndSettings.CatalogPageLen;
|
||||||
|
|
@ -190,44 +187,25 @@ namespace isnd.Services
|
||||||
{
|
{
|
||||||
if (i >= this.isndSettings.CatalogPageLen)
|
if (i >= this.isndSettings.CatalogPageLen)
|
||||||
{
|
{
|
||||||
page = new RegistrationPage(basepageid, extUrl)
|
page = new RegistrationPage(bidreg, extUrl)
|
||||||
{
|
{
|
||||||
CommitId = commit.CommitId,
|
CommitId = commit.CommitId,
|
||||||
CommitTimeStamp = commit.CommitTimeStamp
|
CommitTimeStamp = commit.CommitTimeStamp
|
||||||
};
|
};
|
||||||
CurrentCatalogPages.Add(page);
|
CurrentCatalogIndex.Items.Add(page);
|
||||||
var pageRef = new RegistrationPage(page.Id, extUrl)
|
|
||||||
{
|
|
||||||
CommitId = commit.CommitId,
|
|
||||||
CommitTimeStamp = commit.CommitTimeStamp
|
|
||||||
};
|
|
||||||
CurrentCatalogIndex.Items.Add(pageRef);
|
|
||||||
i = 0;
|
i = 0;
|
||||||
}
|
}
|
||||||
var validPkgs = dbContext.Packages
|
var validPkgs = (await dbContext.Packages
|
||||||
.Include(po => po.Owner)
|
.Include(po => po.Owner)
|
||||||
.Include(pkg => pkg.Versions)
|
.Include(pkg => pkg.Versions)
|
||||||
.Include(pkg => pkg.LatestVersion)
|
.Include(pkg => pkg.LatestVersion)
|
||||||
.ToList()
|
.ToArrayAsync())
|
||||||
.GroupBy((q) => q.Id);
|
.GroupBy((q) => q.Id);
|
||||||
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
|
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
|
||||||
foreach (var pkgid in validPkgs)
|
foreach (var pkgid in validPkgs)
|
||||||
{
|
{
|
||||||
StringBuilder refid = new StringBuilder(bidreg);
|
StringBuilder refid = new(bidreg);
|
||||||
refid.AppendFormat("{0}/",
|
refid.AppendFormat("{0}/", pkgid.Key);
|
||||||
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"
|
|
||||||
}; */
|
|
||||||
foreach (var pkgv in pkgid)
|
foreach (var pkgv in pkgid)
|
||||||
page.AddVersionRange(pkgv.Versions);
|
page.AddVersionRange(pkgv.Versions);
|
||||||
}
|
}
|
||||||
|
|
@ -280,7 +258,7 @@ namespace isnd.Services
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<PackageVersion> GetCatalogLeaf(string pkgId, string semver=null, string pkgType=null)
|
public IEnumerable<PackageVersion> GetCatalogLeaf(string pkgId, string semver = null, string pkgType = null)
|
||||||
{
|
{
|
||||||
return dbContext.PackageVersions
|
return dbContext.PackageVersions
|
||||||
.Include(v => v.Package)
|
.Include(v => v.Package)
|
||||||
|
|
@ -309,9 +287,9 @@ namespace isnd.Services
|
||||||
.Include(v => v.Package)
|
.Include(v => v.Package)
|
||||||
.Include(v => v.Package.Owner)
|
.Include(v => v.Package.Owner)
|
||||||
.Include(v => v.LatestCommit)
|
.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))
|
&& (pkgType == null || pkgType == v.Type))
|
||||||
.OrderByDescending(p=> p.CommitNId)
|
.OrderByDescending(p => p.CommitNId)
|
||||||
.Select(p => p.ToLeave(bid, extUrl))
|
.Select(p => p.ToLeave(bid, extUrl))
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
@ -327,13 +305,12 @@ namespace isnd.Services
|
||||||
public async Task<RegistrationPageIndex> GetPackageRegistrationIndexAsync(RegistrationPageIndexQuery query)
|
public async Task<RegistrationPageIndex> GetPackageRegistrationIndexAsync(RegistrationPageIndexQuery query)
|
||||||
{
|
{
|
||||||
// RegistrationPageIndexAndQuery
|
// RegistrationPageIndexAndQuery
|
||||||
var scope = (await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
var scope = await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
||||||
.ToListAsync()) .Where(p => MatchingExact(p, query));
|
.Where(p => MatchingExact(p, query)).Skip(query.Skip).Take(query.Take).ToListAsync();
|
||||||
var total = scope.Count();
|
|
||||||
var pkgs = scope.Skip(query.Skip).Take(query.Take).ToArray();
|
|
||||||
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}";
|
||||||
return
|
return
|
||||||
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
|
new RegistrationPageIndex(bid, query.Query, extUrl, scope);
|
||||||
}
|
}
|
||||||
public async Task<RegistrationPageIndex> SearchPackageAsync(RegistrationPageIndexQuery query)
|
public async Task<RegistrationPageIndex> SearchPackageAsync(RegistrationPageIndexQuery query)
|
||||||
{
|
{
|
||||||
|
|
@ -342,25 +319,25 @@ namespace isnd.Services
|
||||||
if (query.Query == null) query.Query = "";
|
if (query.Query == null) query.Query = "";
|
||||||
var scope = (await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
var scope = (await dbContext.Packages.Include(p => p.Versions).Include(p => p.Owner)
|
||||||
.ToListAsync())
|
.ToListAsync())
|
||||||
.Where(p => Matching(p,query))
|
.Where(p => Matching(p, query))
|
||||||
;
|
;
|
||||||
var total = scope.Count();
|
var total = scope.Count();
|
||||||
var pkgs = scope.Skip(query.Skip).Take(query.Take);
|
var pkgs = scope.Skip(query.Skip).Take(query.Take);
|
||||||
|
|
||||||
return
|
return
|
||||||
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
|
new RegistrationPageIndex(bid, query.Query, extUrl, pkgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool MatchingExact(Package p, RegistrationPageIndexQuery query)
|
private static bool MatchingExact(Package p, RegistrationPageIndexQuery query)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
p.Id.Equals(query.Query, StringComparison.InvariantCultureIgnoreCase)
|
p.Id == query.Query
|
||||||
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease));
|
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool Matching(Package p, RegistrationPageIndexQuery query)
|
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));
|
&& (query.Prerelease || p.Versions.Any(v => !v.IsPrerelease));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue