Skip to content

Commit 5573cc7

Browse files
committed
Fixes rare exception when using GetLocalizedPropertyCollection with large entity IDs array
1 parent d8a2a4e commit 5573cc7

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/Libraries/SmartStore.Services/Localization/LocalizedEntityService.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ protected virtual LocalizedPropertyCollection GetLocalizedPropertyCollectionInte
218218
where x.LocaleKeyGroup == localeKeyGroup
219219
select x;
220220

221+
var splitEntityIds = false;
221222
var requestedSet = entityIds;
222223

223224
if (entityIds != null && entityIds.Length > 0)
@@ -243,7 +244,15 @@ protected virtual LocalizedPropertyCollection GetLocalizedPropertyCollectionInte
243244
else
244245
{
245246
requestedSet = entityIds;
246-
query = query.Where(x => entityIds.Contains(x.EntityId));
247+
248+
if (entityIds.Length > 5000)
249+
{
250+
splitEntityIds = true;
251+
}
252+
else
253+
{
254+
query = query.Where(x => entityIds.Contains(x.EntityId));
255+
}
247256
}
248257
}
249258

@@ -252,7 +261,20 @@ protected virtual LocalizedPropertyCollection GetLocalizedPropertyCollectionInte
252261
query = query.Where(x => x.LanguageId == languageId);
253262
}
254263

255-
return new LocalizedPropertyCollection(localeKeyGroup, requestedSet, query.ToList());
264+
if (splitEntityIds)
265+
{
266+
var items = new List<LocalizedProperty>();
267+
foreach (var chunk in entityIds.Slice(5000))
268+
{
269+
items.AddRange(query.Where(x => chunk.Contains(x.EntityId)).ToList());
270+
}
271+
272+
return new LocalizedPropertyCollection(localeKeyGroup, requestedSet, items);
273+
}
274+
else
275+
{
276+
return new LocalizedPropertyCollection(localeKeyGroup, requestedSet, query.ToList());
277+
}
256278
}
257279
}
258280

0 commit comments

Comments
 (0)