From 576d0ef05647d5b480c31597b859a7982fa9756e Mon Sep 17 00:00:00 2001 From: Cristian Petruta Date: Mon, 26 Sep 2022 15:02:31 -0700 Subject: [PATCH] Writing extended update metadata to the query result JSON is now optional. This greatly reduces the JSON size when update applicability rules not required in the output. --- src/tools/upsync/CommandLineOptions.cs | 3 ++ .../MicrosoftUpdateMetadata.cs | 33 ++++++++++++------- src/tools/upsync/upsync.csproj | 6 ++-- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/tools/upsync/CommandLineOptions.cs b/src/tools/upsync/CommandLineOptions.cs index a50433c..c79f781 100644 --- a/src/tools/upsync/CommandLineOptions.cs +++ b/src/tools/upsync/CommandLineOptions.cs @@ -283,6 +283,9 @@ namespace Microsoft.PackageGraph.Utilitites.Upsync [Option("json-out-path", Required = false, HelpText = "Save results as JSON to the specified path")] public string JsonOutPath { get; set; } + + [Option("include-extended-metadata", Required = false, Default = false, HelpText = "Include extended metadata when saving to JSON query result.")] + public bool IncludeExtendedMetadata { get; set; } } [Verb("match-driver", HelpText = "Find drivers")] diff --git a/src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs b/src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs index 18f6828..593d306 100644 --- a/src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs +++ b/src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs @@ -65,23 +65,32 @@ namespace Microsoft.PackageGraph.Utilitites.Upsync { var packagesList = filteredPackages.ToList(); + if (!options.IncludeExtendedMetadata) + { + // Remove extended metadata unless explicitly requested. + // Applicability rules can be very large but of little interest + packagesList.ForEach(p => p.ApplicabilityRules.Clear()); + } + Console.WriteLine("-----------------------------"); Console.WriteLine($"Query returned {packagesList.Count} entries."); - Console.WriteLine($"Writing results to {options.JsonOutPath}."); - - using (var targetJsonFile = File.Create(options.JsonOutPath)) + if (!options.CountOnly) { - var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Formatting = Formatting.Indented }); - using (var jsonWriter = new StreamWriter(targetJsonFile)) - { - serializer.Serialize(jsonWriter, packagesList); - } - - } + Console.WriteLine($"Writing results to {options.JsonOutPath}."); - - Console.WriteLine($"Query result saved to {options.JsonOutPath}."); + using (var targetJsonFile = File.Create(options.JsonOutPath)) + { + var serializer = JsonSerializer.Create(new JsonSerializerSettings() { Formatting = Formatting.Indented }); + using (var jsonWriter = new StreamWriter(targetJsonFile)) + { + serializer.Serialize(jsonWriter, packagesList); + } + + } + + Console.WriteLine($"Query result saved to {options.JsonOutPath}."); + } } else { diff --git a/src/tools/upsync/upsync.csproj b/src/tools/upsync/upsync.csproj index 4fcb0ff..d03c220 100644 --- a/src/tools/upsync/upsync.csproj +++ b/src/tools/upsync/upsync.csproj @@ -10,9 +10,9 @@ ..\..\..\out\upsync False - 3.0.2.0 - 3.0.2.0 - 3.0.2.0 + 3.0.3.0 + 3.0.3.0 + 3.0.3.0