3

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

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

如何提高索引频率?

4

1 回答 1

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);
    }
于 2015-01-16T18:41:06.227 回答