Skip to content

Commit

Permalink
Merge branch 'siteserver:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
liangminhua committed Jun 15, 2021
2 parents c518612 + 0660f1f commit b731cbd
Show file tree
Hide file tree
Showing 74 changed files with 777 additions and 406 deletions.
8 changes: 7 additions & 1 deletion src/Datory/Repository.Generic.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Datory.Utils;

namespace Datory
Expand All @@ -7,7 +8,7 @@ public partial class Repository<T> : IRepository<T> where T : Entity, new()
{
public IDatabase Database { get; }
public string TableName { get; }
public List<TableColumn> TableColumns { get; }
public List<TableColumn> TableColumns { get; private set; }
public IRedis Redis { get; }

public Repository(IDatabase database)
Expand Down Expand Up @@ -39,5 +40,10 @@ public Repository(IDatabase database, string tableName, IRedis redis)
TableColumns = ReflectionUtils.GetTableColumns(typeof(T));
Redis = redis;
}

public async Task LoadTableColumnsAsync(string tableName)
{
TableColumns = await Database.GetTableColumnsAsync(tableName);
}
}
}
2 changes: 1 addition & 1 deletion src/Datory/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Datory.Utils
{
internal static class ReflectionUtils
public static class ReflectionUtils
{
private static readonly ConcurrentDictionary<RuntimeTypeHandle, IEnumerable<PropertyInfo>> TypeProperties = new ConcurrentDictionary<RuntimeTypeHandle, IEnumerable<PropertyInfo>>();

Expand Down
50 changes: 28 additions & 22 deletions src/SSCMS.Core/Repositories/ChannelRepository.Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Datory;
using SqlKata;
using SSCMS.Dto;
using SSCMS.Enums;
using SSCMS.Models;
Expand Down Expand Up @@ -313,46 +315,50 @@ private void GetChildIdsRecursive(List<ChannelSummary> summaries, List<int> list
}
}

public async Task<List<int>> GetChannelIdsAsync(int siteId, int channelId, ScopeType scopeType)
public async Task<List<int>> GetChannelIdsAsync(int siteId, int channelId, ScopeType scopeType, Query query = null)
{
if (siteId == 0 || channelId == 0) return new List<int>();
var channelIds = new List<int>();

if (siteId == 0 || channelId == 0) return channelIds;

if (scopeType == ScopeType.Self)
{
return new List<int>{ channelId };
channelIds = new List<int>{ channelId };
}

if (scopeType == ScopeType.SelfAndChildren)
else if (scopeType == ScopeType.SelfAndChildren)
{
var summaries = await GetSummariesAsync(siteId);
var list = GetChildIds(summaries, channelId);
list.Add(channelId);
return list;
channelIds = GetChildIds(summaries, channelId);
channelIds.Add(channelId);
}

if (scopeType == ScopeType.Children)
else if (scopeType == ScopeType.Children)
{
var summaries = await GetSummariesAsync(siteId);
return GetChildIds(summaries, channelId);
channelIds = GetChildIds(summaries, channelId);
}

if (scopeType == ScopeType.Descendant)
else if (scopeType == ScopeType.Descendant)
{
var summaries = await GetSummariesAsync(siteId);
var list = new List<int>();
GetChildIdsRecursive(summaries, list, channelId);
return list;
GetChildIdsRecursive(summaries, channelIds, channelId);
}

if (scopeType == ScopeType.All)
else if (scopeType == ScopeType.All)
{
var summaries = await GetSummariesAsync(siteId);
var list = new List<int> { channelId };
GetChildIdsRecursive(summaries, list, channelId);
return list;
channelIds = new List<int> { channelId };
GetChildIdsRecursive(summaries, channelIds, channelId);
}

return new List<int>();
if (query != null)
{
var q = query.Clone();
q.Select(nameof(Channel.Id));
q.Where(nameof(Channel.SiteId), siteId);

var list = await _repository.GetAllAsync<int>(q);
channelIds = channelIds.Intersect<int>(list).ToList();
}

return channelIds;
}

public async Task<List<int>> GetChannelIdsAsync(Channel channel, ScopeType scopeType, string group, string groupNot, string contentModelPluginId)
Expand Down
8 changes: 4 additions & 4 deletions src/SSCMS.Core/Repositories/ChannelRepository.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ namespace SSCMS.Core.Repositories
{
public partial class ChannelRepository
{
public async Task<List<KeyValuePair<int, Channel>>> ParserGetChannelsAsync(int siteId, int pageChannelId, string group, string groupNot, bool isImageExists, bool isImage, int startNum, int totalNum, TaxisType order, ScopeType scopeType, bool isTotal)
public async Task<List<KeyValuePair<int, Channel>>> ParserGetChannelsAsync(int siteId, int pageChannelId, string group, string groupNot, bool isImageExists, bool isImage, int startNum, int totalNum, TaxisType order, ScopeType scopeType, bool isTotal, Query query)
{
var channels = new List<Channel>();

List<int> channelIdList;
if (isTotal)//从所有栏目中选择
{
channelIdList = await GetChannelIdsAsync(siteId, siteId, ScopeType.All);
channelIdList = await GetChannelIdsAsync(siteId, siteId, ScopeType.All, query);
}
else
{
channelIdList = await GetChannelIdsAsync(siteId, pageChannelId, scopeType);
channelIdList = await GetChannelIdsAsync(siteId, pageChannelId, scopeType, query);
}

foreach (var channelId in channelIdList)
Expand Down Expand Up @@ -140,4 +140,4 @@ private static List<Channel> ParserOrder(List<Channel> channels, TaxisType taxis
return channels.OrderBy(x => x.Taxis).ToList();
}
}
}
}
16 changes: 8 additions & 8 deletions src/SSCMS.Core/Repositories/ContentRepository.Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task TrashContentsAsync(Site site, Channel channel, List<int> conte
{
if (contentIdList == null || !contentIdList.Any()) return;

var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

var cacheKeys = new List<string>
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public async Task TrashContentsAsync(Site site, int channelId, int adminId)

public async Task TrashContentAsync(Site site, Channel channel, int contentId, int adminId)
{
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

var cacheKeys = new List<string>
{
Expand Down Expand Up @@ -92,7 +92,7 @@ public async Task DeletePreviewAsync(Site site, Channel channel)
{
if (!channel.IsPreviewContentsExists) return;

var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);
await repository.DeleteAsync(Q
.Where(nameof(Content.SiteId), site.Id)
.Where(nameof(Content.ChannelId), channel.Id)
Expand All @@ -108,7 +108,7 @@ public async Task DeleteTrashAsync(Site site, int channelId, string tableName, L
{
if (contentIdList == null || contentIdList.Count == 0) return;

var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);

var cacheKeys = new List<string>
{
Expand Down Expand Up @@ -164,7 +164,7 @@ public async Task DeleteTrashAsync(Site site, IPluginManager pluginManager)
var tableNames = await _siteRepository.GetTableNamesAsync(site);
foreach (var tableName in tableNames)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);

var channelIds = await repository.GetAllAsync<int>(Q
.Select(nameof(Content.ChannelId))
Expand Down Expand Up @@ -193,7 +193,7 @@ public async Task RestoreTrashAsync(Site site, int restoreChannelId)
var tableNames = await _siteRepository.GetTableNamesAsync(site);
foreach (var tableName in tableNames)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);

var cacheKeys = new List<string>
{
Expand Down Expand Up @@ -223,7 +223,7 @@ public async Task RestoreTrashAsync(Site site, int channelId, string tableName,
{
if (contentIdList == null || contentIdList.Count == 0) return;

var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);

var cacheKeys = new List<string>
{
Expand All @@ -244,7 +244,7 @@ public async Task RestoreTrashAsync(Site site, int channelId, string tableName,
private async Task DeleteReferenceContentsAsync(Site site, ContentSummary summary)
{
var channel = await _channelRepository.GetAsync(summary.ChannelId);
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

await repository.DeleteAsync(
GetQuery(site.Id, channel.Id)
Expand Down
16 changes: 8 additions & 8 deletions src/SSCMS.Core/Repositories/ContentRepository.Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class ContentRepository
{
public async Task<int> GetMaxTaxisAsync(Site site, Channel channel, bool isTop)
{
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

var maxTaxis = 0;
if (isTop)
Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task<int> GetMaxTaxisAsync(Site site, Channel channel, bool isTop)

private async Task<List<ContentSummary>> GetReferenceIdListAsync(string tableName, IEnumerable<int> contentIdList)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);
return await repository.GetAllAsync<ContentSummary>(Q
.Select(nameof(Content.Id), nameof(Content.ChannelId))
.Where(nameof(Content.ChannelId), ">", 0)
Expand All @@ -66,7 +66,7 @@ private async Task<List<ContentSummary>> GetReferenceIdListAsync(string tableNam

public async Task<int> GetFirstContentIdAsync(Site site, IChannelSummary channel)
{
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);
return await repository.GetAsync<int>(Q
.Select(nameof(Content.Id))
.Where(nameof(Content.ChannelId), channel.Id)
Expand All @@ -82,7 +82,7 @@ public async Task<int> GetCountOfContentUpdateAsync(string tableName, int siteId

private async Task<int> GetCountOfContentUpdateAsync(string tableName, int siteId, List<int> channelIdList, DateTime begin, DateTime end, int adminId)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);
var query = Q.Where(nameof(Content.SiteId), siteId);
query.WhereIn(nameof(Content.ChannelId), channelIdList);
query.WhereBetween(nameof(Content.LastModifiedDate), begin, end.AddDays(1));
Expand All @@ -97,7 +97,7 @@ private async Task<int> GetCountOfContentUpdateAsync(string tableName, int siteI

public async Task<List<int>> GetContentIdsBySameTitleAsync(Site site, Channel channel, string title)
{
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

return await repository.GetAllAsync<int>(GetQuery(site.Id, channel.Id)
.Select(nameof(Content.Id))
Expand All @@ -113,7 +113,7 @@ public async Task<int> GetCountOfContentAddAsync(string tableName, int siteId, i

private async Task<int> GetCountOfContentAddAsync(string tableName, int siteId, List<int> channelIdList, DateTime begin, DateTime end, int adminId, bool? checkedState)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);

var query = Q.Where(nameof(Content.SiteId), siteId);
query.WhereIn(nameof(Content.ChannelId), channelIdList);
Expand All @@ -133,13 +133,13 @@ private async Task<int> GetCountOfContentAddAsync(string tableName, int siteId,

public async Task<List<ContentSummary>> GetSummariesAsync(string tableName, Query query)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);
return await repository.GetAllAsync<ContentSummary>(query);
}

public async Task<int> GetCountAsync(string tableName, Query query)
{
var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);
return await repository.CountAsync(query);
}

Expand Down
4 changes: 2 additions & 2 deletions src/SSCMS.Core/Repositories/ContentRepository.Insert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private async Task<int> SyncTaxisAsync(Site site, Channel channel, Content conte
var taxis = content.Taxis;
var updateHigher = false;

var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

var query = Q
.Where(nameof(Content.ChannelId), channel.Id)
Expand Down Expand Up @@ -113,7 +113,7 @@ public async Task<int> InsertWithTaxisAsync(Site site, Channel channel, Content
var tableName = _channelRepository.GetTableName(site, channel);
if (string.IsNullOrEmpty(tableName)) return 0;

var repository = GetRepository(tableName);
var repository = await GetRepositoryAsync(tableName);
if (content.SourceId == SourceManager.Preview)
{
await repository.InsertAsync(content);
Expand Down
2 changes: 1 addition & 1 deletion src/SSCMS.Core/Repositories/ContentRepository.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public async Task<List<ContentSummary>> GetSummariesAsync(IDatabaseManager datab
if (!await _channelRepository.IsExistsAsync(channelId)) return null;

var channel = await _channelRepository.GetAsync(channelId);
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);

query = GetQuery(query, site.Id)
.Select(
Expand Down
10 changes: 5 additions & 5 deletions src/SSCMS.Core/Repositories/ContentRepository.Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public partial class ContentRepository
{
public async Task<List<ContentSummary>> SearchAsync(Site site, Channel channel, bool isAllContents, string searchType, string searchText, bool isAdvanced, List<int> checkedLevels, bool isTop, bool isRecommend, bool isHot, bool isColor, List<string> groupNames, List<string> tagNames)
{
var repository = GetRepository(site, channel);
var repository = await GetRepositoryAsync(site, channel);
var query = Q.Select(nameof(Content.ChannelId), nameof(Content.Id));

await QueryWhereAsync(query, site, channel.Id, isAllContents);
Expand Down Expand Up @@ -98,7 +98,7 @@ public async Task<List<ContentSummary>> SearchAsync(Site site, Channel channel,

public async Task<(int Total, List<ContentSummary> PageSummaries)> UserWriteSearchAsync(int userId, Site site, int page, int? channelId, bool isCheckedLevels, List<int> checkedLevels, List<string> groupNames, List<string> tagNames)
{
var repository = GetRepository(site.TableName);
var repository = await GetRepositoryAsync(site.TableName);

var query = Q
.Select(nameof(Content.ChannelId), nameof(Content.Id))
Expand Down Expand Up @@ -162,7 +162,7 @@ public async Task<(int Total, List<ContentSummary> PageSummaries)> UserWriteSear

public async Task<(int Total, List<ContentSummary> PageSummaries)> AdvancedSearchAsync(Site site, int page, List<int> channelIds, bool isAllContents, DateTime? startDate, DateTime? endDate, IEnumerable<KeyValuePair<string, string>> items, bool isCheckedLevels, List<int> checkedLevels, bool isTop, bool isRecommend, bool isHot, bool isColor, List<string> groupNames, List<string> tagNames, bool isAdmin, int adminId, bool isUser)
{
var repository = GetRepository(site.TableName);
var repository = await GetRepositoryAsync(site.TableName);

var idList = new List<int>(channelIds);
if (isAllContents)
Expand Down Expand Up @@ -292,7 +292,7 @@ public async Task<(int Total, List<ContentSummary> PageSummaries)> AdvancedSearc

public async Task<(int Total, List<ContentSummary> PageSummaries)> CheckSearchAsync(Site site, int page, int? channelId, DateTime? startDate, DateTime? endDate, IEnumerable<KeyValuePair<string, string>> items, bool isCheckedLevels, List<int> checkedLevels, bool isTop, bool isRecommend, bool isHot, bool isColor, List<string> groupNames, List<string> tagNames)
{
var repository = GetRepository(site.TableName);
var repository = await GetRepositoryAsync(site.TableName);

var query = Q
.Select(nameof(Content.ChannelId), nameof(Content.Id))
Expand Down Expand Up @@ -390,7 +390,7 @@ public async Task<(int Total, List<ContentSummary> PageSummaries)> CheckSearchAs

public async Task<(int Total, List<ContentSummary> PageSummaries)> RecycleSearchAsync(Site site, int page, int? channelId, DateTime? startDate, DateTime? endDate, IEnumerable<KeyValuePair<string, string>> items, bool isCheckedLevels, List<int> checkedLevels, bool isTop, bool isRecommend, bool isHot, bool isColor, List<string> groupNames, List<string> tagNames)
{
var repository = GetRepository(site.TableName);
var repository = await GetRepositoryAsync(site.TableName);

var query = Q
.Select(nameof(Content.ChannelId), nameof(Content.Id))
Expand Down

0 comments on commit b731cbd

Please sign in to comment.