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" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||
<PackageReference Include="GitVersion.MsBuild" Version="5.6.10*" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../isn.abst/isn.abst.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -31,10 +31,10 @@ namespace isnd.Data.Catalog
|
|||
Bid = bid;
|
||||
Parent = Bid + $"/{pkgid}/index.json";
|
||||
DlBase = dlBase;
|
||||
this.items = new List<PackageVersion>(items);
|
||||
this.items = new List<PackageVersion>();
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// no The array of registration leaves and their associate metadata
|
||||
/// </summary>
|
||||
|
|
@ -75,9 +53,27 @@ namespace isnd.Data.Catalog
|
|||
public void AddVersionRange(IEnumerable<PackageVersion> 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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The highest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ namespace isnd.Data.Catalog
|
|||
|
||||
public RegistrationPageIndex(string bid, string id, string dlBase, IEnumerable<Package> pkgs)
|
||||
{
|
||||
|
||||
Items = new List<RegistrationPage>();
|
||||
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<RegistrationPage> Items { get; set; }
|
||||
|
|
|
|||
|
|
@ -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 Task<RegistrationPageIndex>GetCatalogIndexAsync()
|
||||
public virtual async Task<RegistrationPageIndex> GetCatalogIndexAsync()
|
||||
{
|
||||
return await ÛpdateCatalogForAsync(null);
|
||||
}
|
||||
|
|
@ -175,14 +174,12 @@ namespace isnd.Services
|
|||
public async Task<RegistrationPageIndex> Û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<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;
|
||||
i = isndSettings.CatalogPageLen;
|
||||
|
|
@ -190,44 +187,25 @@ namespace isnd.Services
|
|||
{
|
||||
if (i >= this.isndSettings.CatalogPageLen)
|
||||
{
|
||||
page = new RegistrationPage(basepageid, extUrl)
|
||||
page = new RegistrationPage(bidreg, extUrl)
|
||||
{
|
||||
CommitId = commit.CommitId,
|
||||
CommitTimeStamp = commit.CommitTimeStamp
|
||||
};
|
||||
CurrentCatalogPages.Add(page);
|
||||
var pageRef = new RegistrationPage(page.Id, 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<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
|
||||
.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<RegistrationPageIndex> 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<RegistrationPageIndex> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue