diff --git a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs
index 4ebe4ad67e..0e3a6f88d5 100644
--- a/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/RepositoryBase.cs
@@ -133,18 +133,13 @@ namespace Umbraco.Core.Persistence.Repositories
///
public IEnumerable GetAll(params TId[] ids)
{
- //ensure they are de-duplicated, easy win if people don't do this as this can cause many excess queries
- ids = ids.Distinct()
- //don't query by anything that is a default of T (like a zero)
- //TODO: I think we should enabled this in case accidental calls are made to get all with invalid ids
- //.Where(x => Equals(x, default(TId)) == false)
- .ToArray();
-
if (ids.Length > 2000)
{
throw new InvalidOperationException("Cannot perform a query with more than 2000 parameters");
}
+ TEntity[] entityCollection = {};
+
if (ids.Any())
{
var entities = _cache.GetByIds(
@@ -153,6 +148,25 @@ namespace Umbraco.Core.Persistence.Repositories
if (ids.Count().Equals(entities.Count()) && entities.Any(x => x == null) == false)
return entities.Select(x => (TEntity)x);
+
+ if (ids.Any())
+ {
+ entityCollection = PerformGetAll(ids)
+ //ensure we don't include any null refs in the returned collection!
+ .WhereNotNull()
+ .ToArray();
+
+ //We need to put a threshold here! IF there's an insane amount of items
+ // coming back here we don't want to chuck it all into memory, this added cache here
+ // is more for convenience when paging stuff temporarily
+
+ if (entityCollection.Length > 100) return entityCollection;
+
+ foreach (var entity in entityCollection.Where(entity => entity != null))
+ {
+ _cache.Save(typeof(TEntity), entity);
+ }
+ }
}
else
{
@@ -169,25 +183,6 @@ namespace Umbraco.Core.Persistence.Repositories
}
}
- var entityCollection = PerformGetAll(ids)
- //ensure we don't include any null refs in the returned collection!
- .WhereNotNull()
- .ToArray();
-
- //We need to put a threshold here! IF there's an insane amount of items
- // coming back here we don't want to chuck it all into memory, this added cache here
- // is more for convenience when paging stuff temporarily
-
- if (entityCollection.Length > 100) return entityCollection;
-
- foreach (var entity in entityCollection)
- {
- if (entity != null)
- {
- _cache.Save(typeof(TEntity), entity);
- }
- }
-
return entityCollection;
}