diff options
author | therzok <marius.ungureanu@xamarin.com> | 2018-11-22 19:12:01 +0300 |
---|---|---|
committer | therzok <marius.ungureanu@xamarin.com> | 2018-11-22 19:12:03 +0300 |
commit | 5a4e5005cf6dfe3a768684264e90dabef9af8d22 (patch) | |
tree | c160c451a2f5ea34ee92482e687daf7d2af93852 /main/src/addins/MonoDevelop.UnitTesting | |
parent | 30f907cc5211c725a7b750e0f32a152ae64b8a09 (diff) |
[Tests] Prune the results store when more than 30 test runs are available
This should improve performance of loading the test results store when
too many results are stored.
Fixes VSTS #586003 - AbstractResultsStore never prunes data
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting')
-rw-r--r-- | main/src/addins/MonoDevelop.UnitTesting/Services/AbstractResultsStore.cs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractResultsStore.cs b/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractResultsStore.cs index 9377430b1d..62b40b80b6 100644 --- a/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractResultsStore.cs +++ b/main/src/addins/MonoDevelop.UnitTesting/Services/AbstractResultsStore.cs @@ -31,6 +31,7 @@ using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Linq; using System.Xml.Serialization; using MonoDevelop.Core; @@ -323,22 +324,34 @@ namespace MonoDevelop.UnitTesting DateTime[] GetStoreDates (string configuration) { if (!Directory.Exists (basePath)) - return new DateTime [0]; + return Array.Empty<DateTime> (); lock (cachedRootList) { DateTime [] res = (DateTime [])cachedRootList [configuration]; if (res != null) return res; - var dates = new List<DateTime> (); + var dates = new List<(string File, DateTime Date)> (); var escapedConfiguration = EscapeFilename (configuration); foreach (string file in Directory.GetFiles (basePath, storeId + "-" + escapedConfiguration + "-*")) { try { DateTime t = ParseFileNameDate (escapedConfiguration, Path.GetFileName (file)); - dates.Add (t); + dates.Add ((file, t)); } catch { } } - res = dates.ToArray (); + + // prune items from the list + // items are sorted due to how the file name is generated + const int maxStoreItems = 30; + int overflow = dates.Count - maxStoreItems; + int toRemove = Math.Max (0, overflow); + if (toRemove != 0) { + for (int i = 0; i < toRemove; ++i) + File.Delete (dates [i].File); + dates.RemoveRange (0, toRemove); + } + + res = dates.Select (x => x.Date).ToArray (); cachedRootList [configuration] = res; return res; } |