Skip to content

Commit

Permalink
Serialize query results using a stream writer to fix out of memory er…
Browse files Browse the repository at this point in the history
…rors.
  • Loading branch information
Almost-Done committed Sep 23, 2022
1 parent 542f6c4 commit f46d325
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 14 additions & 2 deletions src/tools/upsync/PackageMetadataPrint/MicrosoftUpdateMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,22 @@ public static void PrintMicrosoftUpdatePackages(QueryMetadataOptions options, IM
{
var packagesList = filteredPackages.ToList();

File.WriteAllText(options.JsonOutPath, JsonConvert.SerializeObject(packagesList, Formatting.Indented));

Console.WriteLine("-----------------------------");
Console.WriteLine($"Query returned {packagesList.Count} entries.");

Console.WriteLine($"Writing results 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
Expand Down
6 changes: 3 additions & 3 deletions src/tools/upsync/upsync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<Description></Description>
<BaseOutputPath>..\..\..\out\upsync</BaseOutputPath>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<FileVersion>3.0.0.0</FileVersion>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<ProductVersion>3.0.0.0</ProductVersion>
<FileVersion>3.0.2.0</FileVersion>
<AssemblyVersion>3.0.2.0</AssemblyVersion>
<ProductVersion>3.0.2.0</ProductVersion>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit f46d325

Please sign in to comment.