gpt4 book ai didi

nuget - NuGet Gallery 搜索索引应何时更新?

转载 作者:行者123 更新时间:2023-12-01 23:50:21 27 4
gpt4 key购买 nike

我最近根据 GitHub 上的说明安装了本地 NuGet 库.

当我通过 UI 上传包时,它似乎工作正常,但使用命令行推送的包不会显示在搜索结果中。在程序包窗口中,它显示“搜索索引上次更新时间为 55 分钟前”。这对应于我上次发布网站的时间。什么决定了搜索索引何时运行?快速浏览一下代码,它看起来就像您添加/删除包时应该发生的那样,但它似乎并没有这样做。

如何提高索引频率?

最佳答案

在 NuGetGallery 项目中,转到 CreatePackageInternal /Controllers/ApiController 中的方法并在 return 之前调用此行声明。

IndexingService.UpdateIndex(true);

你的代码必须是这样的

    private async Task<ActionResult> CreatePackageInternal()
{
// Get the user
var user = GetCurrentUser();

using (var packageToPush = ReadPackageFromRequest())
{
if (packageToPush.Metadata.MinClientVersion > typeof(Manifest).Assembly.GetName().Version)
{
return new HttpStatusCodeWithBodyResult(HttpStatusCode.BadRequest, String.Format(
CultureInfo.CurrentCulture,
Strings.UploadPackage_MinClientVersionOutOfRange,
packageToPush.Metadata.MinClientVersion));
}

// Ensure that the user can push packages for this partialId.
var packageRegistration = PackageService.FindPackageRegistrationById(packageToPush.Metadata.Id);
if (packageRegistration != null)
{
if (!packageRegistration.IsOwner(user))
{
return new HttpStatusCodeWithBodyResult(HttpStatusCode.Forbidden, Strings.ApiKeyNotAuthorized);
}

// Check if a particular Id-Version combination already exists. We eventually need to remove this check.
string normalizedVersion = packageToPush.Metadata.Version.ToNormalizedString();
bool packageExists =
packageRegistration.Packages.Any(
p => String.Equals(
p.NormalizedVersion,
normalizedVersion,
StringComparison.OrdinalIgnoreCase));

if (packageExists)
{
return new HttpStatusCodeWithBodyResult(
HttpStatusCode.Conflict,
String.Format(CultureInfo.CurrentCulture, Strings.PackageExistsAndCannotBeModified,
packageToPush.Metadata.Id, packageToPush.Metadata.Version.ToNormalizedStringSafe()));
}
}

var package = PackageService.CreatePackage(packageToPush, user, commitChanges: false);
AutoCuratePackage.Execute(package, packageToPush, commitChanges: false);
EntitiesContext.SaveChanges();

using (Stream uploadStream = packageToPush.GetStream())
{
await PackageFileService.SavePackageFileAsync(package, uploadStream);
}
}

IndexingService.UpdateIndex(true);

return new HttpStatusCodeResult(HttpStatusCode.Created);
}

关于nuget - NuGet Gallery 搜索索引应何时更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26885663/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com