Lazily creates the static queries instead of eagerly, this fixes an issue of if these services are accessed before Umbraco has booted
This commit is contained in:
@@ -94,13 +94,7 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
return ProcessQuery(sql);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Queries
|
||||
|
||||
private readonly IQuery<IContent> _publishedQuery = Query<IContent>.Builder.Where(x => x.Published == true);
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Overrides of PetaPocoRepositoryBase<IContent>
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
#region Static Queries
|
||||
|
||||
private readonly IQuery<IContent> _notTrashedQuery = Query<IContent>.Builder.Where(x => x.Trashed == false);
|
||||
private IQuery<IContent> _notTrashedQuery;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -793,6 +793,12 @@ namespace Umbraco.Core.Services
|
||||
/// <returns></returns>
|
||||
internal IEnumerable<IContent> GetAllPublished()
|
||||
{
|
||||
//create it once if it is needed (no need for locking here)
|
||||
if (_notTrashedQuery == null)
|
||||
{
|
||||
_notTrashedQuery = Query<IContent>.Builder.Where(x => x.Trashed == false);
|
||||
}
|
||||
|
||||
using (var repository = RepositoryFactory.CreateContentRepository(UowProvider.GetUnitOfWork()))
|
||||
{
|
||||
return repository.GetByPublishedVersion(_notTrashedQuery);
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace Umbraco.Core.Services
|
||||
|
||||
#region Static Queries
|
||||
|
||||
private readonly IQuery<IUmbracoEntity> _rootEntityQuery = Query<IUmbracoEntity>.Builder.Where(x => x.ParentId == -1);
|
||||
private IQuery<IUmbracoEntity> _rootEntityQuery;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -392,6 +392,12 @@ namespace Umbraco.Core.Services
|
||||
/// <returns>An enumerable list of <see cref="IUmbracoEntity"/> objects</returns>
|
||||
public virtual IEnumerable<IUmbracoEntity> GetRootEntities(UmbracoObjectTypes umbracoObjectType)
|
||||
{
|
||||
//create it once if it is needed (no need for locking here)
|
||||
if (_rootEntityQuery == null)
|
||||
{
|
||||
_rootEntityQuery = Query<IUmbracoEntity>.Builder.Where(x => x.ParentId == -1);
|
||||
}
|
||||
|
||||
var objectTypeId = umbracoObjectType.GetGuid();
|
||||
using (var repository = RepositoryFactory.CreateEntityRepository(UowProvider.GetUnitOfWork()))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user