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

Cache if package maintainer is an author of the package to avoid multiple API calls #13111

Merged
merged 1 commit into from
Jul 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/DynamoPackages/PackageManagerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public class PackageManagerClient
/// The directory where new packages are created during the upload process.
/// </summary>
private readonly string packageUploadDirectory;

/// <summary>
/// The dictionay stores the package name corresponding to the boolean result of whether the user is an author of that package or not.
/// </summary>
private Dictionary<string, bool> packageMaintainers;

/// <summary>
/// The URL of the package manager website
Expand All @@ -47,6 +52,7 @@ internal PackageManagerClient(IGregClient client, IPackageUploadBuilder builder,
this.packageUploadDirectory = packageUploadDirectory;
this.uploadBuilder = builder;
this.client = client;
this.packageMaintainers = new Dictionary<string, bool>();
}

internal bool Upvote(string packageId)
Expand Down Expand Up @@ -277,9 +283,15 @@ internal PackageManagerResult Undeprecate(string name)

internal bool DoesCurrentUserOwnPackage(Package package,string username)
{
bool value;
if (this.packageMaintainers.Count > 0 && this.packageMaintainers.TryGetValue(package.Name, out value)) {
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
return value;
}
var pkg = new PackageInfo(package.Name, new Version(package.VersionName));
var mnt = GetPackageMaintainers(pkg);
return (mnt != null) && (mnt.maintainers.Any(maintainer => maintainer.username.Equals(username)));
value = (mnt != null) && (mnt.maintainers.Any(maintainer => maintainer.username.Equals(username)));
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
this.packageMaintainers[package.Name] = value;
return value;
}
}
}