Skip to content

Commit

Permalink
Performance tweak - only query the entire list of offline channels 1 …
Browse files Browse the repository at this point in the history
…time at startup for a massive decrease in resource usage over the running lifetime of the app

Set border thickness to 0 for NoResizeBorderless window settings.
Refactored calls that duplicated NoResizeBorderless so they all now use that function.
  • Loading branch information
laurencee committed Jan 10, 2016
1 parent a38cbe9 commit 9028e02
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
4 changes: 2 additions & 2 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.8.2.0")]
[assembly: AssemblyFileVersion("1.8.2.0")]
[assembly: AssemblyVersion("1.8.3.0")]
[assembly: AssemblyFileVersion("1.8.3.0")]
1 change: 1 addition & 0 deletions Livestream.Monitor/Core/Utility/WindowSettingsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public WindowSettingsBuilder NoResizeBorderless()
{
WithResizeMode(ResizeMode.NoResize);
WithWindowStyle(WindowStyle.None);
settings.BorderThickness = new Thickness(0);
return this;
}

Expand Down
37 changes: 25 additions & 12 deletions Livestream.Monitor/Model/Monitoring/MonitorStreamsModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
Expand All @@ -18,6 +19,7 @@ public class MonitorStreamsModel : PropertyChangedBase, IMonitorStreamsModel

private bool initialised;
private bool canRefreshLivestreams = true;
private bool queryOfflineStreams = true;
private LivestreamModel selectedLivestream;

#region Design Time Constructor
Expand Down Expand Up @@ -146,19 +148,12 @@ public async Task RefreshLivestreams()
var offlineStreams = Livestreams.Where(x => !onlineStreams.Any(y => y.Channel.Name.IsEqualTo(x.Id))).ToList();
offlineStreams.ForEach(x => x.Offline()); // mark all remaining streams as offline immediately

var offlineTasks = offlineStreams.Select(x => new
if (queryOfflineStreams)
{
Livestream = x,
OfflineData = twitchTvClient.GetChannelDetails(x.Id)
}).ToList();

await Task.WhenAll(offlineTasks.Select(x => x.OfflineData));
foreach (var offlineTask in offlineTasks)
{
var offlineData = offlineTask.OfflineData.Result;
if (offlineData == null) continue;

offlineTask.Livestream.PopulateWithChannel(offlineData);
await QueryOfflineStreams(offlineStreams);
// We only need to query offline streams one time to get the channel info
// It's a waste of resources to query for updates to offline streams
queryOfflineStreams = false;
}
}
catch (Exception)
Expand All @@ -182,6 +177,24 @@ protected virtual void OnOnlineLivestreamsRefreshComplete()
OnlineLivestreamsRefreshComplete?.Invoke(this, EventArgs.Empty);
}

private async Task QueryOfflineStreams(List<LivestreamModel> offlineStreams)
{
var offlineTasks = offlineStreams.Select(x => new
{
Livestream = x,
OfflineData = twitchTvClient.GetChannelDetails(x.Id)
}).ToList();

await Task.WhenAll(offlineTasks.Select(x => x.OfflineData));
foreach (var offlineTask in offlineTasks)
{
var offlineData = offlineTask.OfflineData.Result;
if (offlineData == null) continue;

offlineTask.Livestream.PopulateWithChannel(offlineData);
}
}

private void LoadLivestreams()
{
if (initialised) return;
Expand Down
3 changes: 1 addition & 2 deletions Livestream.Monitor/Model/NotificationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ public void AddNotification(LivestreamNotification livestreamNotification)
private void ShowNotification(LivestreamNotification livestreamNotification)
{
var vmTopLeft = GetNotificationTopLeft(livestreamNotification);
var settings = new WindowSettingsBuilder().WithWindowStyle(WindowStyle.None)
.WithResizeMode(ResizeMode.NoResize)
var settings = new WindowSettingsBuilder().NoResizeBorderless()
.WithTopLeft(vmTopLeft.Y, vmTopLeft.X)
.TransparentBackground()
.AsTopmost()
Expand Down
9 changes: 3 additions & 6 deletions Livestream.Monitor/Model/StreamLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Livestream.Monitor.Core.Utility;
using Livestream.Monitor.Model.Monitoring;
using Livestream.Monitor.ViewModels;
using Livestream.Monitor.Views;

namespace Livestream.Monitor.Model
{
Expand Down Expand Up @@ -184,10 +183,9 @@ private MessageBoxViewModel ShowLivestreamerLoadMessageBox(string title, string
DisplayName = title,
MessageText = messageText
};

var settings = new WindowSettingsBuilder().SizeToContent()
.WithWindowStyle(WindowStyle.ToolWindow)
.WithResizeMode(ResizeMode.NoResize)
.NoResizeBorderless()
.Create();

windowManager.ShowWindow(messageBoxViewModel, null, settings);
Expand All @@ -206,8 +204,7 @@ private bool CheckLivestreamerExists()
};

var settings = new WindowSettingsBuilder().SizeToContent()
.WithWindowStyle(WindowStyle.ToolWindow)
.WithResizeMode(ResizeMode.NoResize)
.NoResizeBorderless()
.Create();

windowManager.ShowWindow(msgBox, null, settings);
Expand Down

0 comments on commit 9028e02

Please sign in to comment.