Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UI for validation tables (just orchestrator tables) #4861

Merged
merged 1 commit into from
Oct 19, 2017
Merged

Add UI for validation tables (just orchestrator tables) #4861

merged 1 commit into from
Oct 19, 2017

Conversation

joelverhagen
Copy link
Member

#4653

Admin page (notice last link)

screencapture-localhost-admin-1508288815230

Initial page

screencapture-localhost-admin-validation-search-1508288756724

Search by ID

screencapture-localhost-admin-validation-search-1508288660270

Search by ID + version

screencapture-localhost-admin-validation-search-1508288671683

Search by validation set tracking ID

screencapture-localhost-admin-validation-search-1508288685885

Search by validation ID

screencapture-localhost-admin-validation-search-1508288704997

@@ -7,12 +7,11 @@
namespace NuGetGallery
{
public interface IEntityRepository<T>
where T : class, IEntity, new()
where T : class, new()
Copy link
Member Author

Choose a reason for hiding this comment

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

Simplified this interface to enable use on the ValidationEntitiesContext.

IPackageVersionModel package,
bool relativeUrl = true)
{
return url.RevalidatePackage(package.Id, package.Version);
Copy link
Contributor

Choose a reason for hiding this comment

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

RevalidatePackage [](start = 23, length = 17)

Pass the relativeUrl down.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

}

[HttpGet]
public virtual async Task<ActionResult> Search(string vq)
Copy link
Contributor

Choose a reason for hiding this comment

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

vq [](start = 62, length = 2)

Nit: vq is a strange name, could we use something like query instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

validation query. I'll give the parameter a different name but I wanted to keep the query string short.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend q instead of vq as an abbreviation for the query string :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking this would collide with filling in the search box at the top of the page, but this behavior only exists on the package search page. Will fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

await SearchByPackageIdAsync(validationSets, line);
}

var outputValidationSets = validationSets
Copy link
Contributor

Choose a reason for hiding this comment

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

outputValidationSets [](start = 16, length = 20)

Nit: return this directly instead of creating a variable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

while ((line = stringReader.ReadLine()) != null)
{
var normalizedLine = Regex.Replace(line.Trim(), @"\s+", " ");
lines.Add(line);
Copy link
Contributor

@loic-sharma loic-sharma Oct 18, 2017

Choose a reason for hiding this comment

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

line [](start = 30, length = 4)

Add the normalizedLine, not the line. Also, skip normalizedLines that are empty.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

string line;
while ((line = stringReader.ReadLine()) != null)
{
var normalizedLine = Regex.Replace(line.Trim(), @"\s+", " ");
Copy link
Contributor

Choose a reason for hiding this comment

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

Replace [](start = 47, length = 7)

Could you run the Regex.Replace once on the entire query instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@{ bool isFirst = true; }
@foreach (var package in Model.Packages)
{
if (!isFirst)
Copy link
Contributor

Choose a reason for hiding this comment

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

isFirst [](start = 13, length = 7)

Should this be if (isFirst)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed entirely.

</thead>
<tbody>
@foreach (var validation in set.PackageValidations)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

{ [](start = 24, length = 1)

Curly brace is off here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

return View();
var viewModel = new HomeViewModel(
showValidation: _config.Current.AsynchronousPackageValidationEnabled);

Copy link
Contributor

Choose a reason for hiding this comment

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

Will this ever be false?

Copy link
Member Author

Choose a reason for hiding this comment

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

The default git clone case is this (and NuGet.org, today).

_packages = packages ?? throw new ArgumentNullException(nameof(packages));
}

public async Task<IReadOnlyList<PackageValidationSet>> SearchAsync(string query)
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be great to have comments at the method level.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

}
}

private async Task SearchByValidationSetKeyAsync(Dictionary<long, PackageValidationSet> validationSets, string line)
Copy link
Contributor

Choose a reason for hiding this comment

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

line argument is more like a key. Can it be renamed to key?

Copy link
Member Author

Choose a reason for hiding this comment

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

Line is not the key in all cases. It is just something that will be parsed for a DB query. I would rather keep the parameter name consistent.

.Include(x => x.PackageValidations)
.Where(x => x.Key == integer)
.FirstOrDefaultAsync();

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the state if the collection has more than 1 element? Should this case be asserted? (same for the other similar methods)

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not possible since Key is the primary key of the PackageValidationSets table.

await SearchByValidationIdAsync(validationSets, line);
await SearchByValidationSetKeyAsync(validationSets, line);
await SearchByPackageIdAndVersionAsync(validationSets, line);
await SearchByPackageIdAsync(validationSets, line);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the order of invocation for these methods matter? Could be cases when they will override dictionary data for one call to the other?

Copy link
Member Author

Choose a reason for hiding this comment

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

Order does not matter since the dictionary contains the whole package validation set.

@@ -172,6 +172,7 @@
<connectionStrings>
<add name="Gallery.SqlServer" connectionString="Data Source=(localdb)\mssqllocaldb; Initial Catalog=NuGetGallery; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="Gallery.SupportRequestSqlServer" connectionString="Data Source=(localdb)\mssqllocaldb; Initial Catalog=SupportRequest; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
<add name="Validation.SqlServer" connectionString="Data Source=(localdb)\mssqllocaldb; Initial Catalog=Validation; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
Copy link
Contributor

Choose a reason for hiding this comment

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

what would be the F5 experience of this? Will someone running the gallery on a clean PC have issue? We don't run migrations for Validation DB as part of the setup-devenvironment.ps1.

Copy link
Member Author

Choose a reason for hiding this comment

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

F5 will not see this validation UI since asynchronous validation is disabled. The setup script should not create this database since it's not the default scenario (IMO).


namespace NuGetGallery.Areas.Admin.Models
{
public enum DeletedStatus
Copy link
Contributor

Choose a reason for hiding this comment

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

PackageDeletedStatus for clearity

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

string line;
while ((line = stringReader.ReadLine()) != null)
{
var normalizedLine = Regex.Replace(line.Trim(), @"\s+", " ");
Copy link
Contributor

Choose a reason for hiding this comment

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

can u add a timeout to the regex. Barry will like it :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

private async Task SearchByValidationSetTrackingIdAsync(Dictionary<long, PackageValidationSet> validationSets, string line)
{
Guid guid;
if (Guid.TryParse(line, out guid))
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: u can define the guid inline

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

private async Task SearchByValidationSetTrackingIdAsync(Dictionary<long, PackageValidationSet> validationSets, string line)
{
Guid guid;
if (Guid.TryParse(line, out guid))
Copy link
Member

Choose a reason for hiding this comment

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

nit: the SearchByX methods are very similar; I wonder if you could refactor for both code reuse and slight optimization.

For instance, if the caller does TryParse it would know whether to call specific SearchByX methods. Also, then you may be able to combine the core _validationSets SearchBy query into a single method that takes a filter.

Copy link
Member Author

Choose a reason for hiding this comment

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

I chose not to perform these optimizations until we experience some painful performance. As the code is today, I think it's more readable.

{
private readonly ValidationEntitiesContext _entities;

public ValidationEntityRepository(ValidationEntitiesContext entities)
Copy link
Member

Choose a reason for hiding this comment

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

Could EntityRepository be made more generic so that it could be reused for Validation? Maybe introduce an IEntitiesContextBase interface for the APIs shared across all EntityContexts:

  • SaveChangesAsync
  • Set
  • DeleteOnCommit
  • SetCommandTimeout
  • GetDatabase

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think an new base interface would help here. I will try to have a shared base class (implementation, not interface).

Copy link
Member Author

Choose a reason for hiding this comment

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

These cannot share a base class since there is not common interface between IEntitiesContext and ValidationEntitiesContext.


namespace NuGetGallery.Areas.Admin.Services
{
public class ValidationAdminService
Copy link
Contributor

Choose a reason for hiding this comment

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

didnt see UTs for this code

Copy link
Member Author

Choose a reason for hiding this comment

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

Spoke extensively offline about this. I think they are not necessary in this case since the code is pretty simple but I would rather set the pattern here as there is no rush.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@@ -105,5 +106,19 @@
Manage Namespace Reservation
</p>
</li>
@if (Model.ShowValidation)
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach. We show items in this menu that are not relevant for certain configs, and we shouldn't.

@joelverhagen joelverhagen merged commit 1ecbca2 into NuGet:dev Oct 19, 2017
@joelverhagen joelverhagen deleted the val-admin branch October 19, 2017 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants