Rollback uses GetVersionsSlim
This commit is contained in:
@@ -19,6 +19,12 @@ namespace Umbraco.Core.Persistence.Repositories
|
||||
/// <remarks>Current version is first, and then versions are ordered with most recent first.</remarks>
|
||||
IEnumerable<TEntity> GetAllVersions(int nodeId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets versions.
|
||||
/// </summary>
|
||||
/// <remarks>Current version is first, and then versions are ordered with most recent first.</remarks>
|
||||
IEnumerable<TEntity> GetAllVersionsSlim(int nodeId, int skip, int take);
|
||||
|
||||
/// <summary>
|
||||
/// Gets version identifiers.
|
||||
/// </summary>
|
||||
|
||||
@@ -53,6 +53,10 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
// gets all versions, current first
|
||||
public abstract IEnumerable<TEntity> GetAllVersions(int nodeId);
|
||||
|
||||
// gets all versions, current first
|
||||
public virtual IEnumerable<TEntity> GetAllVersionsSlim(int nodeId, int skip, int take)
|
||||
=> GetAllVersions(nodeId).Skip(skip).Take(take);
|
||||
|
||||
// gets all version ids, current first
|
||||
public virtual IEnumerable<int> GetVersionIds(int nodeId, int maxRows)
|
||||
{
|
||||
|
||||
@@ -220,6 +220,16 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return MapDtosToContent(Database.Fetch<DocumentDto>(sql), true);
|
||||
}
|
||||
|
||||
public override IEnumerable<IContent> GetAllVersionsSlim(int nodeId, int skip, int take)
|
||||
{
|
||||
var sql = GetBaseQuery(QueryType.Many, false)
|
||||
.Where<NodeDto>(x => x.NodeId == nodeId)
|
||||
.OrderByDescending<ContentVersionDto>(x => x.Current)
|
||||
.AndByDescending<ContentVersionDto>(x => x.VersionDate);
|
||||
|
||||
return MapDtosToContent(Database.Fetch<DocumentDto>(sql), true, true);
|
||||
}
|
||||
|
||||
public override IContent GetVersion(int versionId)
|
||||
{
|
||||
var sql = GetBaseQuery(QueryType.Single, false)
|
||||
@@ -911,7 +921,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
return base.ApplySystemOrdering(ref sql, ordering);
|
||||
}
|
||||
|
||||
private IEnumerable<IContent> MapDtosToContent(List<DocumentDto> dtos, bool withCache = false)
|
||||
private IEnumerable<IContent> MapDtosToContent(List<DocumentDto> dtos, bool withCache = false, bool slim = false)
|
||||
{
|
||||
var temps = new List<TempContent<Content>>();
|
||||
var contentTypes = new Dictionary<int, IContentType>();
|
||||
@@ -944,47 +954,53 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
var c = content[i] = ContentBaseFactory.BuildEntity(dto, contentType);
|
||||
|
||||
// need templates
|
||||
var templateId = dto.DocumentVersionDto.TemplateId;
|
||||
if (templateId.HasValue && templateId.Value > 0)
|
||||
templateIds.Add(templateId.Value);
|
||||
if (dto.Published)
|
||||
if (!slim)
|
||||
{
|
||||
templateId = dto.PublishedVersionDto.TemplateId;
|
||||
// need templates
|
||||
var templateId = dto.DocumentVersionDto.TemplateId;
|
||||
if (templateId.HasValue && templateId.Value > 0)
|
||||
templateIds.Add(templateId.Value);
|
||||
}
|
||||
if (dto.Published)
|
||||
{
|
||||
templateId = dto.PublishedVersionDto.TemplateId;
|
||||
if (templateId.HasValue && templateId.Value > 0)
|
||||
templateIds.Add(templateId.Value);
|
||||
}
|
||||
|
||||
// need properties
|
||||
var versionId = dto.DocumentVersionDto.Id;
|
||||
var publishedVersionId = dto.Published ? dto.PublishedVersionDto.Id : 0;
|
||||
var temp = new TempContent<Content>(dto.NodeId, versionId, publishedVersionId, contentType, c)
|
||||
{
|
||||
Template1Id = dto.DocumentVersionDto.TemplateId
|
||||
};
|
||||
if (dto.Published) temp.Template2Id = dto.PublishedVersionDto.TemplateId;
|
||||
temps.Add(temp);
|
||||
// need properties
|
||||
var versionId = dto.DocumentVersionDto.Id;
|
||||
var publishedVersionId = dto.Published ? dto.PublishedVersionDto.Id : 0;
|
||||
var temp = new TempContent<Content>(dto.NodeId, versionId, publishedVersionId, contentType, c)
|
||||
{
|
||||
Template1Id = dto.DocumentVersionDto.TemplateId
|
||||
};
|
||||
if (dto.Published) temp.Template2Id = dto.PublishedVersionDto.TemplateId;
|
||||
temps.Add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
// load all required templates in 1 query, and index
|
||||
var templates = _templateRepository.GetMany(templateIds.ToArray())
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
|
||||
// load all properties for all documents from database in 1 query - indexed by version id
|
||||
var properties = GetPropertyCollections(temps);
|
||||
|
||||
// assign templates and properties
|
||||
foreach (var temp in temps)
|
||||
if (!slim)
|
||||
{
|
||||
// complete the item
|
||||
if (temp.Template1Id.HasValue && templates.TryGetValue(temp.Template1Id.Value, out var template))
|
||||
temp.Content.Template = template;
|
||||
if (temp.Template2Id.HasValue && templates.TryGetValue(temp.Template2Id.Value, out template))
|
||||
temp.Content.PublishTemplate = template;
|
||||
temp.Content.Properties = properties[temp.VersionId];
|
||||
// load all required templates in 1 query, and index
|
||||
var templates = _templateRepository.GetMany(templateIds.ToArray())
|
||||
.ToDictionary(x => x.Id, x => x);
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
temp.Content.ResetDirtyProperties(false);
|
||||
// load all properties for all documents from database in 1 query - indexed by version id
|
||||
var properties = GetPropertyCollections(temps);
|
||||
|
||||
// assign templates and properties
|
||||
foreach (var temp in temps)
|
||||
{
|
||||
// complete the item
|
||||
if (temp.Template1Id.HasValue && templates.TryGetValue(temp.Template1Id.Value, out var template))
|
||||
temp.Content.Template = template;
|
||||
if (temp.Template2Id.HasValue && templates.TryGetValue(temp.Template2Id.Value, out template))
|
||||
temp.Content.PublishTemplate = template;
|
||||
temp.Content.Properties = properties[temp.VersionId];
|
||||
|
||||
// reset dirty initial properties (U4-1946)
|
||||
temp.Content.ResetDirtyProperties(false);
|
||||
}
|
||||
}
|
||||
|
||||
// set variations, if varying
|
||||
|
||||
@@ -134,6 +134,12 @@ namespace Umbraco.Core.Services
|
||||
/// <remarks>Versions are ordered with current first, then most recent first.</remarks>
|
||||
IEnumerable<IContent> GetVersions(int id);
|
||||
|
||||
/// <summary>
|
||||
/// Gets all versions of a document.
|
||||
/// </summary>
|
||||
/// <remarks>Versions are ordered with current first, then most recent first.</remarks>
|
||||
IEnumerable<IContent> GetVersionsSlim(int id, int skip, int take);
|
||||
|
||||
/// <summary>
|
||||
/// Gets top versions of a document.
|
||||
/// </summary>
|
||||
|
||||
@@ -474,6 +474,19 @@ namespace Umbraco.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a collection of an <see cref="IContent"/> objects versions by Id
|
||||
/// </summary>
|
||||
/// <returns>An Enumerable list of <see cref="IContent"/> objects</returns>
|
||||
public IEnumerable<IContent> GetVersionsSlim(int id, int skip, int take)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
scope.ReadLock(Constants.Locks.ContentTree);
|
||||
return _documentRepository.GetAllVersionsSlim(id, skip, take);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of all version Ids for the given content item ordered so latest is first
|
||||
/// </summary>
|
||||
|
||||
@@ -1706,14 +1706,16 @@ namespace Umbraco.Web.Editors
|
||||
public IEnumerable<RollbackVersion> GetRollbackVersions(int contentId, string culture = null)
|
||||
{
|
||||
var rollbackVersions = new List<RollbackVersion>();
|
||||
var writerIds = new HashSet<int>();
|
||||
|
||||
//Return a list of all versions of a specific content node
|
||||
var versions = Services.ContentService.GetVersions(contentId);
|
||||
//Return a list of all versions of a specific content node
|
||||
// fixme - cap at 50 versions for now?
|
||||
var versions = Services.ContentService.GetVersionsSlim(contentId, 0, 50);
|
||||
|
||||
//Not all nodes are variants & thus culture can be null
|
||||
//Only filter the collection
|
||||
if (culture != null)
|
||||
{
|
||||
//Get cultures that were published with the version = their update date is equal to the version's
|
||||
versions = versions.Where(x => x.UpdateDate == x.GetUpdateDate(culture));
|
||||
}
|
||||
|
||||
@@ -1722,20 +1724,26 @@ namespace Umbraco.Web.Editors
|
||||
|
||||
foreach (var version in versions)
|
||||
{
|
||||
var rollbackVersion = new RollbackVersion();
|
||||
|
||||
//Version ID
|
||||
rollbackVersion.VersionId = version.VersionId;
|
||||
|
||||
//Date of version
|
||||
rollbackVersion.VersionDate = version.UpdateDate;
|
||||
|
||||
//Name of writer/publisher/user
|
||||
var writerId = version.WriterId;
|
||||
var user = Services.UserService.GetUserById(writerId);
|
||||
rollbackVersion.VersionAuthorName = user.Name;
|
||||
var rollbackVersion = new RollbackVersion
|
||||
{
|
||||
VersionId = version.VersionId,
|
||||
VersionDate = version.UpdateDate,
|
||||
VersionAuthorId = version.WriterId
|
||||
};
|
||||
|
||||
rollbackVersions.Add(rollbackVersion);
|
||||
|
||||
writerIds.Add(version.WriterId);
|
||||
}
|
||||
|
||||
var users = Services.UserService
|
||||
.GetUsersById(writerIds.ToArray())
|
||||
.ToDictionary(x => x.Id, x => x.Name);
|
||||
|
||||
foreach (var rollbackVersion in rollbackVersions)
|
||||
{
|
||||
if (users.TryGetValue(rollbackVersion.VersionAuthorId, out var userName))
|
||||
rollbackVersion.VersionAuthorName = userName;
|
||||
}
|
||||
|
||||
return rollbackVersions;
|
||||
|
||||
@@ -12,6 +12,9 @@ namespace Umbraco.Web.Models.ContentEditing
|
||||
[DataMember(Name = "versionDate")]
|
||||
public DateTime VersionDate { get; set; }
|
||||
|
||||
[DataMember(Name = "versionAuthorId")]
|
||||
public int VersionAuthorId { get; set; }
|
||||
|
||||
[DataMember(Name = "versionAuthorName")]
|
||||
public string VersionAuthorName { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user