-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSettingsService.cs
More file actions
48 lines (40 loc) · 1.54 KB
/
SettingsService.cs
File metadata and controls
48 lines (40 loc) · 1.54 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
using System.Diagnostics;
using System.Threading.Tasks;
using api.Models.Common;
using api.Models.ProfileEditor;
using api.Models.Ttv;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
namespace api.Services
{
public class SettingsService : ISettingsService
{
private readonly TtvContext _ttvContext;
private readonly ILogger<SettingsService> _logger;
public SettingsService(TtvContext ttvContext, ILogger<SettingsService> logger)
{
_ttvContext = ttvContext;
_logger = logger;
}
public async Task<ProfileSettings> GetProfileSettings(int userprofileId, bool forElasticsearch = false)
{
var stopwatch = Stopwatch.StartNew();
DimUserProfile dup = await _ttvContext.DimUserProfiles
.AsNoTracking()
.FirstOrDefaultAsync(up => up.Id == userprofileId);
var profileSettings = new ProfileSettings()
{
Hidden = dup?.Hidden,
PublishNewData = dup?.PublishNewOrcidData,
HighlightOpeness = dup?.HighlightOpeness
};
stopwatch.Stop();
if (stopwatch.ElapsedMilliseconds > Constants.LoggingParameters.SLOW_OPERATION_MS_THRESHOLD)
{
_logger.LogWarning($"GetProfileSettings is slow. userprofileId={userprofileId}, forElasticsearch={forElasticsearch} in {stopwatch.ElapsedMilliseconds}ms.");
}
return profileSettings;
}
}
}