Skip to content

Commit

Permalink
VCST-846: Fix QuerySplittingBehavior.SingleQuery Warning in Platform (#…
Browse files Browse the repository at this point in the history
…2804)

fix: The query uses the 'First'/'FirstOrDefault' operator without 'OrderBy' and filter operators. This may lead to unpredictable results.
feat: Enables AsSplitQuery policy for queries. This behavior can improve performance when the query ApplicationUser, Settings and Dynamic Properties.
  • Loading branch information
OlegoO authored Jun 26, 2024
1 parent b79dcf4 commit 104c9d6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public virtual async Task<DynamicPropertyEntity[]> GetObjectDynamicPropertiesAsy
{
var properties = await DynamicProperties.Include(x => x.DisplayNames)
.OrderBy(x => x.Name)
.Where(x => objectTypes.Contains(x.ObjectType)).ToArrayAsync();
.Where(x => objectTypes.Contains(x.ObjectType))
.AsSplitQuery()
.ToArrayAsync();
return properties;
}

Expand All @@ -48,6 +50,7 @@ public virtual async Task<DynamicPropertyDictionaryItemEntity[]> GetDynamicPrope

var retVal = await DynamicPropertyDictionaryItems.Include(x => x.DisplayNames)
.Where(x => ids.Contains(x.Id))
.AsSplitQuery()
.ToArrayAsync();
return retVal;
}
Expand All @@ -62,6 +65,7 @@ public virtual async Task<DynamicPropertyEntity[]> GetDynamicPropertiesByIdsAsyn
var retVal = await DynamicProperties.Include(x => x.DisplayNames)
.Where(x => ids.Contains(x.Id))
.OrderBy(x => x.Name)
.AsSplitQuery()
.ToArrayAsync();
return retVal;
}
Expand All @@ -76,6 +80,7 @@ public virtual async Task<DynamicPropertyEntity[]> GetDynamicPropertiesForTypesA
var retVal = await DynamicProperties.Include(p => p.DisplayNames)
.Where(p => objectTypes.Contains(p.ObjectType))
.OrderBy(p => p.Name)
.AsSplitQuery()
.ToArrayAsync();
return retVal;
}
Expand All @@ -87,6 +92,7 @@ public virtual async Task<SettingEntity[]> GetObjectSettingsByNamesAsync(string[
.Where(x => x.ObjectId == objectId && x.ObjectType == objectType)
.Where(x => names.Contains(x.Name))
.OrderBy(x => x.Name)
.AsSplitQuery()
.ToArrayAsync();
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public virtual async Task SaveObjectSettingsAsync(IEnumerable<ObjectSettingEntry
var alreadyExistDbSettings = (await repository.Settings
.Include(s => s.SettingValues)
.Where(x => settingNames.Contains(x.Name))
.AsSplitQuery()
.ToListAsync());

var validator = new ObjectSettingEntryValidator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ public async Task<UserSearchResult> SearchUsersAsync(UserSearchCriteria criteria
{
sortInfos = new[] { new SortInfo { SortColumn = ReflectionUtility.GetPropertyName<ApplicationUser>(x => x.UserName), SortDirection = SortDirection.Descending } };
}
result.Results = await query.OrderBySortInfos(sortInfos).Skip(criteria.Skip).Take(criteria.Take).ToArrayAsync();

result.Results = await query
.OrderBySortInfos(sortInfos)
.Skip(criteria.Skip)
.Take(criteria.Take)
.AsSplitQuery()
.ToArrayAsync();

foreach (var user in result.Results)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ public IEnumerable<AppDescriptor> GetApps()
return apps;

}
}
}
6 changes: 3 additions & 3 deletions src/VirtoCommerce.Platform.Web/Licensing/LicenseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public License GetLicense()

using (var repository = _platformRepositoryFactory())
{
rawLicenseData = repository.RawLicenses?.FirstOrDefault()?.Data;
rawLicenseData = repository.RawLicenses.OrderBy(x => x.Id).FirstOrDefault()?.Data;
}

var license = License.Parse(rawLicenseData, _platformOptions.LicensePublicKeyResourceName);
Expand All @@ -40,13 +40,13 @@ public void SaveLicense(License license)
{
using (var repository = _platformRepositoryFactory())
{
var rawLicense = repository.RawLicenses?.FirstOrDefault();
var rawLicense = repository.RawLicenses.OrderBy(x => x.Id).FirstOrDefault();
if (rawLicense == null)
{
rawLicense = new Data.Model.RawLicenseEntity();
repository.Add(rawLicense);
}
rawLicense.Data = license.RawLicense;
rawLicense.Data = license.RawLicense;
repository.UnitOfWork.Commit();
}
}
Expand Down

0 comments on commit 104c9d6

Please sign in to comment.