Browse Source

Rearrange indexes, changed to DeleteWithRepliesAsync, used BasicAggregateRoot for CMS Kit.

pull/5067/head
Halil İbrahim Kalkan 6 years ago
parent
commit
04a79dac48
  1. 1198
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200815101508_ReArrange_Indexes.Designer.cs
  2. 103
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200815101508_ReArrange_Indexes.cs
  3. 12
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs
  4. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs
  5. 9
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  6. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/UserReaction.cs
  7. 16
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  8. 15
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs
  9. 2
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitEntityFrameworkCoreModule.cs
  10. 1
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/ICmsKitDbContext.cs
  11. 19
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  12. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs
  13. 4
      modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs

1198
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200815101508_ReArrange_Indexes.Designer.cs

File diff suppressed because it is too large

103
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20200815101508_ReArrange_Indexes.cs

@ -0,0 +1,103 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Volo.CmsKit.Migrations
{
public partial class ReArrange_Indexes : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_CmsUserReactions_EntityType_EntityId",
table: "CmsUserReactions");
migrationBuilder.DropIndex(
name: "IX_CmsUserReactions_CreatorId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions");
migrationBuilder.DropIndex(
name: "IX_CmsComments_RepliedCommentId",
table: "CmsComments");
migrationBuilder.DropIndex(
name: "IX_CmsComments_EntityType_EntityId",
table: "CmsComments");
migrationBuilder.CreateIndex(
name: "IX_CmsUsers_TenantId_Email",
table: "CmsUsers",
columns: new[] { "TenantId", "Email" });
migrationBuilder.CreateIndex(
name: "IX_CmsUsers_TenantId_UserName",
table: "CmsUsers",
columns: new[] { "TenantId", "UserName" });
migrationBuilder.CreateIndex(
name: "IX_CmsUserReactions_TenantId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions",
columns: new[] { "TenantId", "EntityType", "EntityId", "ReactionName" });
migrationBuilder.CreateIndex(
name: "IX_CmsUserReactions_TenantId_CreatorId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions",
columns: new[] { "TenantId", "CreatorId", "EntityType", "EntityId", "ReactionName" });
migrationBuilder.CreateIndex(
name: "IX_CmsComments_TenantId_RepliedCommentId",
table: "CmsComments",
columns: new[] { "TenantId", "RepliedCommentId" });
migrationBuilder.CreateIndex(
name: "IX_CmsComments_TenantId_EntityType_EntityId",
table: "CmsComments",
columns: new[] { "TenantId", "EntityType", "EntityId" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_CmsUsers_TenantId_Email",
table: "CmsUsers");
migrationBuilder.DropIndex(
name: "IX_CmsUsers_TenantId_UserName",
table: "CmsUsers");
migrationBuilder.DropIndex(
name: "IX_CmsUserReactions_TenantId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions");
migrationBuilder.DropIndex(
name: "IX_CmsUserReactions_TenantId_CreatorId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions");
migrationBuilder.DropIndex(
name: "IX_CmsComments_TenantId_RepliedCommentId",
table: "CmsComments");
migrationBuilder.DropIndex(
name: "IX_CmsComments_TenantId_EntityType_EntityId",
table: "CmsComments");
migrationBuilder.CreateIndex(
name: "IX_CmsUserReactions_EntityType_EntityId",
table: "CmsUserReactions",
columns: new[] { "EntityType", "EntityId" });
migrationBuilder.CreateIndex(
name: "IX_CmsUserReactions_CreatorId_EntityType_EntityId_ReactionName",
table: "CmsUserReactions",
columns: new[] { "CreatorId", "EntityType", "EntityId", "ReactionName" });
migrationBuilder.CreateIndex(
name: "IX_CmsComments_RepliedCommentId",
table: "CmsComments",
column: "RepliedCommentId");
migrationBuilder.CreateIndex(
name: "IX_CmsComments_EntityType_EntityId",
table: "CmsComments",
columns: new[] { "EntityType", "EntityId" });
}
}
}

12
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs

@ -950,9 +950,9 @@ namespace Volo.CmsKit.Migrations
b.HasKey("Id");
b.HasIndex("RepliedCommentId");
b.HasIndex("TenantId", "RepliedCommentId");
b.HasIndex("EntityType", "EntityId");
b.HasIndex("TenantId", "EntityType", "EntityId");
b.ToTable("CmsComments");
});
@ -992,9 +992,9 @@ namespace Volo.CmsKit.Migrations
b.HasKey("Id");
b.HasIndex("EntityType", "EntityId");
b.HasIndex("TenantId", "EntityType", "EntityId", "ReactionName");
b.HasIndex("CreatorId", "EntityType", "EntityId", "ReactionName");
b.HasIndex("TenantId", "CreatorId", "EntityType", "EntityId", "ReactionName");
b.ToTable("CmsUserReactions");
});
@ -1060,6 +1060,10 @@ namespace Volo.CmsKit.Migrations
b.HasKey("Id");
b.HasIndex("TenantId", "Email");
b.HasIndex("TenantId", "UserName");
b.ToTable("CmsUsers");
});

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs

@ -7,7 +7,7 @@ using Volo.Abp.MultiTenancy;
namespace Volo.CmsKit.Comments
{
public class Comment: Entity<Guid>, IAggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator, IMultiTenant
public class Comment: BasicAggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }

9
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Repositories;
@ -10,7 +11,13 @@ namespace Volo.CmsKit.Comments
{
Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType,
[NotNull] string entityId
[NotNull] string entityId,
CancellationToken cancellationToken = default
);
Task DeleteWithRepliesAsync(
Guid id,
CancellationToken cancellationToken = default
);
}
}

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/UserReaction.cs

@ -7,7 +7,7 @@ using Volo.Abp.MultiTenancy;
namespace Volo.CmsKit.Reactions
{
public class UserReaction : Entity<Guid>, IAggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator, IMultiTenant
public class UserReaction : BasicAggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator, IMultiTenant
{
public virtual Guid? TenantId { get; protected set; }

16
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -22,7 +22,8 @@ namespace Volo.CmsKit.Comments
public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId)
string entityId,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
@ -37,10 +38,12 @@ namespace Volo.CmsKit.Comments
Author = user
};
return await query.ToListAsync();
return await query.ToListAsync(GetCancellationToken(cancellationToken));
}
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
public async Task DeleteWithRepliesAsync(
Guid id,
CancellationToken cancellationToken = default)
{
var replies = await DbSet
.Where(x => x.RepliedCommentId == id)
@ -49,10 +52,13 @@ namespace Volo.CmsKit.Comments
foreach (var reply in replies)
{
//TODO: Discuss if it is better to mark it as deleted and show in the ui as "This is deleted" instead of deleting it and replies completely
await base.DeleteAsync(reply.Id, autoSave, GetCancellationToken(cancellationToken));
await base.DeleteAsync(
reply.Id,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
await base.DeleteAsync(id, autoSave, GetCancellationToken(cancellationToken));
await base.DeleteAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
}
}
}

15
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -32,6 +32,9 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.ConfigureByConvention();
b.ConfigureAbpUser();
b.HasIndex(x => new {x.TenantId, x.UserName});
b.HasIndex(x => new {x.TenantId, x.Email});
});
if (GlobalFeatureManager.Instance.IsEnabled<ReactionsFeature>())
@ -39,15 +42,15 @@ namespace Volo.CmsKit.EntityFrameworkCore
builder.Entity<UserReaction>(b =>
{
b.ToTable(options.TablePrefix + "UserReactions", options.Schema);
b.ConfigureByConvention();
b.Property(x => x.EntityType).IsRequired().HasMaxLength(UserReactionConsts.MaxEntityTypeLength);
b.Property(x => x.EntityId).IsRequired().HasMaxLength(UserReactionConsts.MaxEntityIdLength);
b.Property(x => x.ReactionName).IsRequired().HasMaxLength(UserReactionConsts.MaxReactionNameLength);
b.Property(x => x.CreationTime);
b.HasIndex(x => new { x.EntityType, x.EntityId });
b.HasIndex(x => new { x.CreatorId, x.EntityType, x.EntityId, x.ReactionName });
b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId, x.ReactionName });
b.HasIndex(x => new { x.TenantId, x.CreatorId, x.EntityType, x.EntityId, x.ReactionName });
});
}
@ -56,16 +59,16 @@ namespace Volo.CmsKit.EntityFrameworkCore
builder.Entity<Comment>(b =>
{
b.ToTable(options.TablePrefix + "Comments", options.Schema);
b.ConfigureByConvention();
b.Property(x => x.EntityType).IsRequired().HasMaxLength(CommentConsts.MaxEntityTypeLength);
b.Property(x => x.EntityId).IsRequired().HasMaxLength(CommentConsts.MaxEntityIdLength);
b.Property(x => x.Text).IsRequired().HasMaxLength(CommentConsts.MaxTextLength);
b.Property(x => x.RepliedCommentId);
b.Property(x => x.CreationTime);
b.HasIndex(x => new { x.EntityType, x.EntityId });
b.HasIndex(x => new { x.RepliedCommentId });
b.HasIndex(x => new { x.TenantId, x.EntityType, x.EntityId });
b.HasIndex(x => new { x.TenantId, x.RepliedCommentId });
});
}
}

2
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitEntityFrameworkCoreModule.cs

@ -19,9 +19,9 @@ namespace Volo.CmsKit.EntityFrameworkCore
{
context.Services.AddAbpDbContext<CmsKitDbContext>(options =>
{
options.AddRepository<CmsUser, EfCoreCmsUserRepository>();
options.AddRepository<UserReaction, EfCoreUserReactionRepository>();
options.AddRepository<Comment, EfCoreCommentRepository>();
options.AddRepository<CmsUser, EfCoreCmsUserRepository>();
});
}
}

1
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/ICmsKitDbContext.cs

@ -6,5 +6,6 @@ namespace Volo.CmsKit.EntityFrameworkCore
[ConnectionStringName(CmsKitDbProperties.ConnectionStringName)]
public interface ICmsKitDbContext : IEfCoreDbContext
{
}
}

19
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -20,7 +20,8 @@ namespace Volo.CmsKit.MongoDB.Comments
public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType,
string entityId)
string entityId,
CancellationToken cancellationToken = default)
{
Check.NotNullOrWhiteSpace(entityType, nameof(entityType));
Check.NotNullOrWhiteSpace(entityId, nameof(entityId));
@ -31,11 +32,12 @@ namespace Volo.CmsKit.MongoDB.Comments
orderby comment.CreationTime
select user;
var authors = await authorsQuery.ToListAsync();
var authors = await authorsQuery.ToListAsync(GetCancellationToken(cancellationToken));
var comments = await GetMongoQueryable()
.Where(c => c.EntityId == entityId && c.EntityType == entityType)
.OrderBy(c => c.CreationTime).ToListAsync();
.OrderBy(c => c.CreationTime)
.ToListAsync(GetCancellationToken(cancellationToken));
return comments
.Select(
@ -47,7 +49,9 @@ namespace Volo.CmsKit.MongoDB.Comments
}).ToList();
}
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default)
public async Task DeleteWithRepliesAsync(
Guid id,
CancellationToken cancellationToken = default)
{
var replies = await GetMongoQueryable()
.Where(x => x.RepliedCommentId == id)
@ -56,10 +60,13 @@ namespace Volo.CmsKit.MongoDB.Comments
foreach (var reply in replies)
{
//TODO: Discuss if it is better to mark it as deleted and show in the ui as "This is deleted" instead of deleting it and replies completely
await base.DeleteAsync(reply.Id, autoSave, GetCancellationToken(cancellationToken));
await base.DeleteAsync(
reply,
cancellationToken: GetCancellationToken(cancellationToken)
);
}
await base.DeleteAsync(id, autoSave, GetCancellationToken(cancellationToken));
await base.DeleteAsync(id, cancellationToken: GetCancellationToken(cancellationToken));
}
}
}

2
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

@ -90,7 +90,7 @@ namespace Volo.CmsKit.Public.Comments
throw new BusinessException();
}
await CommentRepository.DeleteAsync(id);
await CommentRepository.DeleteWithRepliesAsync(id);
}
private List<CommentWithDetailsDto> ConvertCommentsToNestedStructure(List<CommentWithAuthorQueryResultItem> comments)

4
modules/cms-kit/test/Volo.CmsKit.TestBase/Comments/CommentRepository_Tests.cs

@ -30,9 +30,9 @@ namespace Volo.CmsKit.Comments
}
[Fact]
public async Task DeleteAsync()
public async Task DeleteWithRepliesAsync()
{
await _commentRepository.DeleteAsync(_cmsKitTestData.CommentWithChildId);
await _commentRepository.DeleteWithRepliesAsync(_cmsKitTestData.CommentWithChildId);
var list = await _commentRepository.GetListAsync();

Loading…
Cancel
Save