Skip to content

Commit b15dc77

Browse files
authored
Improve perf when reading build info from web (#121)
1 parent 21b30a4 commit b15dc77

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

GUI/MainForm.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,11 @@ private async void MainForm_Load(object sender, EventArgs e) {
316316
if (lastUpdDateTimeServer > lastUpdDateTimeLocal) { // if the server timestamp > local timestamp, prompt to download
317317
var res = MessageBox.Show(this,
318318
"The SQLBuildInfo.json file was updated recently on GitHub. Do you wish to update your copy with the newer version?",
319-
"SQL Build info updated", MessageBoxButtons.YesNo);
319+
"SQL build info updated", MessageBoxButtons.YesNo);
320320

321321
if (DialogResult.Yes == res) {
322322
t = sqlBuildInfoURLs.Select(jsonURL => Utils.GetTextFromUrl(jsonURL)).ToArray();
323+
this.UpdateStatus("Trying to update SQL build info from GitHub...");
323324
taskRes = (await Task.WhenAll(t)).Where(s => !string.IsNullOrWhiteSpace(s));
324325
if (taskRes.Any()) { // update local copy of build info file
325326
using var writer = new StreamWriter(SqlBuildInfoFileName);
@@ -328,9 +329,10 @@ private async void MainForm_Load(object sender, EventArgs e) {
328329
writer.Close();
329330
using var wr = new StreamWriter(LastUpdatedTimestampFileName, false); // update local last updated timestamp
330331
wr.Write(lastUpdDateTimeServer.ToString(LastUpdatedTimestampFormat, new CultureInfo(LastUpdatedTimestampCulture)));
332+
this.UpdateStatus("Successfully updated SQL build info!");
331333
wr.Flush();
332334
wr.Close();
333-
} else MessageBox.Show(this, "Could not download the SQL Build Info file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
335+
} else MessageBox.Show(this, "Could not download the SQL build Info file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
334336
}
335337
}
336338
}

GUI/Utils.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ internal static async Task<string> GetTextFromUrl(string url) {
4141
using var req = new HttpRequestMessage(HttpMethod.Get, url);
4242
using var res = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead);
4343
res.EnsureSuccessStatusCode();
44-
return await res.Content.ReadAsStringAsync();
44+
using var ms = new MemoryStream();
45+
await res.Content.CopyToAsync(ms);
46+
ms.Seek(0, SeekOrigin.Begin);
47+
using var sr = new StreamReader(ms);
48+
return sr.ReadToEnd();
4549
} catch (HttpRequestException) { /* this will fall through to the return false so it is okay to leave blank */ } catch (NotSupportedException) { /* this will fall through to the return false so it is okay to leave blank */ }
4650
return null;
4751
}

0 commit comments

Comments
 (0)