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:
Shannon
2016-12-08 12:48:44 +11:00
parent 0415e910dc
commit b413b7b5af
3 changed files with 15 additions and 9 deletions

View File

@@ -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>

View File

@@ -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);

View File

@@ -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()))
{