Skip to content
This repository has been archived by the owner on Mar 16, 2021. It is now read-only.

[Prefix] Display Packages' Verified Status on Search Service #226

Merged
merged 7 commits into from
Aug 24, 2017

Conversation

loic-sharma
Copy link
Contributor

@@ -340,6 +342,7 @@ private static void WriteDataV2(JsonWriter jsonWriter, NuGetIndexSearcher search
WriteDocumentValue(jsonWriter, "ReleaseNotes", document, "ReleaseNotes");
WriteDocumentValue(jsonWriter, "ProjectUrl", document, "ProjectUrl");
WriteDocumentValue(jsonWriter, "IconUrl", document, "IconUrl");
WriteProperty(jsonWriter, "IsVerified", isVerified);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For v2 this needs to be in PackageRegistration object, WriteRegistrationV2 above. See the OneNote spec for the return result structure. Also the key should be "Verified" for V2 search result on the registration object.

@@ -0,0 +1,59 @@
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copyright, and sort usings


namespace NuGet.Indexing
{
public static class VerifiedPackages
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class can be internal. NuGet.Indexing has internals visible to NuGet.IndexingTests.


namespace NuGet.IndexingTests
{
public class VerifiedPackagesParsingTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests should mirror source classes. I would rename to VerifiedPackagesTests.

Also, consider making VerifiedPackages.Parse private and testing through the Load API which is used directly by callers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing the Load method would require mocks that would complicate the test for little gain. Since the Load method is only a convenience method, I think testing the Parse method directly is fine. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No strong opinion here. Generally, I try to test the entry point for complete coverage.

I thought it'd just require a simple mock to have the loader return a reader... but if it's more complex, wouldn't worry about it.

[InlineData("['test']", new string[] { "test" })]
[InlineData("['test', 'test']", new string[] { "test" })]
[InlineData("['test', 'test123']", new string[] { "test", "test123" })]
public void ParsesProperInput(string input, string[] expected)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case insensitive tests?

using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sort usings, System first


while (packageId != null)
{
result.Add(String.Intern(packageId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming String.Intern is intended to optimize lookup performance? Would the string for lookup need to be interned as well, and would the optimization work on a case insensitive collection?

Would measure if this code actually improves perf (i.e., with simple console app), and keep / add comment if it does.

Copy link
Contributor Author

@loic-sharma loic-sharma Aug 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interning strings is a pattern used throughout the search service. String.Intern is to reduce memory pressure, not to improve performance. Each reload allocates a bunch of strings (things like package IDs, versions, etc..) that already exist in memory from the previous index. By interning the string, we can reuse the memory that was allocated the first time that string was encountered. The memory allocated during the index reload will then be collected on the next garbage collection. If we didn't intern the strings, the strings would be allocated on each reload and would need to be freed on the subsequent reload. Since the time between reloads is in the order of minutes, the strings would likely get promoted to the next generation of memory. Garbage collection is cheaper when memory is only used briefly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this documented in code, so we don't accidentally remove it?

@@ -6,6 +6,10 @@
using NuGet.Services.BasicSearchTests.Models;
using NuGet.Services.BasicSearchTests.TestSupport;
using Xunit;
using System.IO;
using Newtonsoft.Json;
using System;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sort

@@ -206,7 +207,7 @@ protected override NuGetIndexSearcher CreateSearcher(IndexReader reader)
}
catch (Exception e)
{
_logger.LogError("NuGetSearcherManager.CreateSearcher: Error loading auxiliary data.", e);
_logger.LogError("NuGetSearcherManager.CreateSearcher - Exception thrown while loading auxiliary data: {Exception}", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if verifiedPackages.json is not found would this exception not reload any aux data? I am worried what would happen if we deployed search service before the job is deployed.

Copy link
Contributor Author

@loic-sharma loic-sharma Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If verifiedPackages.json is not found, the search service will fail to launch and all responses will return UNINITIALIZED. I believe this is the correct pattern to use - if there are issues, the search service should fail so that we are alerted quickly. We should deploy this change only when the auxiliary data is ready to be consumed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update the deployment task to make sure that the order of deployment is important during this deployment. NuGet/NuGetGallery#4591

Copy link
Contributor

@shishirx34 shishirx34 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@loic-sharma loic-sharma merged commit 71a33d2 into dev Aug 24, 2017
@loic-sharma loic-sharma deleted the loshar-verified branch May 1, 2018 20:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants