From 98fb5838b9e8a35594d2bf32b66f511388689f09 Mon Sep 17 00:00:00 2001 From: Anton Sukhorukov Date: Tue, 30 May 2023 15:56:07 +0300 Subject: [PATCH] CompileAsyncQuery: MobileAppInstallRegistrator --- .../Repositories/LoginEventsRepository.cs | 14 ------------- .../Mobile/MobileAppInstallRegistrator.cs | 21 ++++++++++++------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/common/services/ASC.AuditTrail/Repositories/LoginEventsRepository.cs b/common/services/ASC.AuditTrail/Repositories/LoginEventsRepository.cs index f77fefe380..53645753fe 100644 --- a/common/services/ASC.AuditTrail/Repositories/LoginEventsRepository.cs +++ b/common/services/ASC.AuditTrail/Repositories/LoginEventsRepository.cs @@ -109,20 +109,6 @@ public class LoginEventsRepository } return _mapper.Map, IEnumerable>(await query.ToListAsync()); - } - - public async Task GetCountAsync(int tenant, DateTime? from = null, DateTime? to = null) - { - using var messagesContext = _dbContextFactory.CreateDbContext(); - var query = messagesContext.LoginEvents - .Where(l => l.TenantId == tenant); - - if (from.HasValue && to.HasValue) - { - query = query.Where(l => l.Date >= from & l.Date <= to); - } - - return await query.CountAsync(); } } diff --git a/web/ASC.Web.Core/Mobile/MobileAppInstallRegistrator.cs b/web/ASC.Web.Core/Mobile/MobileAppInstallRegistrator.cs index 15193a94cf..e3cc6ff394 100644 --- a/web/ASC.Web.Core/Mobile/MobileAppInstallRegistrator.cs +++ b/web/ASC.Web.Core/Mobile/MobileAppInstallRegistrator.cs @@ -24,6 +24,8 @@ // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode +using Microsoft.EntityFrameworkCore; + namespace ASC.Web.Core.Mobile; [Scope] @@ -54,13 +56,16 @@ public class MobileAppInstallRegistrator : IMobileAppInstallRegistrator public async Task IsInstallRegisteredAsync(string userEmail, MobileAppType? appType) { using var dbContext = _dbContextFactory.CreateDbContext(); - var q = dbContext.MobileAppInstall.Where(r => r.UserEmail == userEmail); - - if (appType.HasValue) - { - q = q.Where(r => r.AppType == (int)appType.Value); - } - - return await q.AnyAsync(); + return await Queries.AnyMobileAppInstallAsync(dbContext, userEmail, appType); } } + +file static class Queries +{ + public static readonly Func> AnyMobileAppInstallAsync = Microsoft.EntityFrameworkCore.EF.CompileAsyncQuery( + (CustomDbContext ctx, string userEmail, MobileAppType? appType) => + ctx.MobileAppInstall + .Where(r => r.UserEmail == userEmail) + .Where(r => appType.HasValue && r.AppType == (int)appType.Value) + .Any()); +}