-
Notifications
You must be signed in to change notification settings - Fork 610
Expand file tree
/
Copy pathMiniProfilerBaseOptionsExtensions.cs
More file actions
55 lines (53 loc) · 2.21 KB
/
MiniProfilerBaseOptionsExtensions.cs
File metadata and controls
55 lines (53 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace StackExchange.Profiling.Internal
{
/// <summary>
/// Internal extension methods for <see cref="MiniProfilerBaseOptions"/> and inheritors.
/// </summary>
public static class MiniProfilerBaseOptionsExtensions
{
/// <summary>
/// Synchronously gets unviewed profiles for the user,
/// expiring any above the <see cref="MiniProfilerBaseOptions.MaxUnviewedProfiles"/> count.
/// </summary>
/// <param name="options">The options to operate against on.</param>
/// <param name="user">The user to get profiler IDs for.</param>
/// <returns>The list of IDs</returns>
public static List<Guid> ExpireAndGetUnviewed(this MiniProfilerBaseOptions options, string user)
{
var ids = options.Storage?.GetUnviewedIds(user);
if (ids?.Count > options.MaxUnviewedProfiles)
{
for (var i = 0; i < ids.Count - options.MaxUnviewedProfiles; i++)
{
options.Storage.SetViewed(user, ids[i]);
}
}
return ids;
}
/// <summary>
/// Asynchronously gets unviewed profiles for the user,
/// expiring any above the <see cref="MiniProfilerBaseOptions.MaxUnviewedProfiles"/> count.
/// </summary>
/// <param name="options">The options to operate against on.</param>
/// <param name="user">The user to get profiler IDs for.</param>
/// <returns>The list of IDs</returns>
public static async Task<List<Guid>> ExpireAndGetUnviewedAsync(this MiniProfilerBaseOptions options, string user)
{
if (options.Storage == null)
{
return null;
}
var ids = await options.Storage.GetUnviewedIdsAsync(user).ConfigureAwait(false);
if (ids?.Count > options.MaxUnviewedProfiles)
{
var idsToSetViewed = ids.Take(ids.Count - options.MaxUnviewedProfiles);
await options.Storage.SetViewedAsync(user, idsToSetViewed).ConfigureAwait(false);
}
return ids;
}
}
}