什么时候NuGet Gallery搜索索引会更新?

时间:2014-11-12 11:17:14

标签: nuget nuget-server nugetgallery

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

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

如何提高索引频率?

1 个答案:

答案 0 :(得分:3)

在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);
    }