Skip to content

Commit

Permalink
fixed performance drop in recent files section
Browse files Browse the repository at this point in the history
  • Loading branch information
MaksimChegulov committed Dec 12, 2024
1 parent 0bed358 commit 5d2ec3a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public async Task<FolderContentDto<T>> GetAsync<T>(T parentId, DataWrapper<T> fo
}

List<FileShareRecord<string>> currentUsersRecords = null;
if (await fileSecurityCommon.IsDocSpaceAdministratorAsync(authContext.CurrentAccount.ID))
if (await fileSecurityCommon.IsDocSpaceAdministratorAsync(authContext.CurrentAccount.ID) &&
folderItems.FolderInfo is { FolderType: FolderType.VirtualRooms or FolderType.Archive })
{
currentUsersRecords = await fileSecurity.GetUserRecordsAsync().ToListAsync();
}
Expand Down
4 changes: 2 additions & 2 deletions products/ASC.Files/Core/Core/Dao/Interfaces/IFileDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ Task<int> GetFilesCountAsync(T parentId, FilterType filterType, bool subjectGrou

Task InitCustomOrder(Dictionary<T, int> fileIds, T parentFolderId);

IAsyncEnumerable<File<T>> GetFilesByTagAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
IAsyncEnumerable<File<T>> GetFilesByTagAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject, OrderBy orderBy, int offset = 0, int count = -1);

Task<int> GetFilesByTagCountAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
Task<int> GetFilesByTagCountAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject);

#endregion
Expand Down
50 changes: 22 additions & 28 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,7 +1722,7 @@ public async Task<Stream> GetThumbnailAsync(File<int> file, int width, int heigh
return await storage.GetReadStreamAsync(string.Empty, path, 0);
}

public async IAsyncEnumerable<File<int>> GetFilesByTagAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
public async IAsyncEnumerable<File<int>> GetFilesByTagAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject, OrderBy orderBy, int offset = 0, int count = -1)
{
if (filterType == FilterType.FoldersOnly)
Expand Down Expand Up @@ -1768,7 +1768,7 @@ public async IAsyncEnumerable<File<int>> GetFilesByTagAsync(Guid? tagOwner, TagT
}
}

public async Task<int> GetFilesByTagCountAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
public async Task<int> GetFilesByTagCountAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject)
{
if (filterType == FilterType.FoldersOnly)
Expand All @@ -1781,7 +1781,7 @@ public async Task<int> GetFilesByTagCountAsync(Guid? tagOwner, TagType tagType,
var q = await GetFilesByTagQuery(tagOwner, tagType, filesDbContext);

q = await GetFilesQueryWithFilters(q, filterType, subjectGroup, subjectId, searchText, extension, searchInContent, excludeSubject);

return await q.CountAsync();
}

Expand Down Expand Up @@ -2328,47 +2328,41 @@ private async Task<IQueryable<T>> GetFilesQueryWithFilters<T>(IQueryable<T> q, F
return q;
}

private async Task<IQueryable<FileByTagQuery>> GetFilesByTagQuery(Guid? tagOwner, TagType tagType, FilesDbContext filesDbContext)
private async Task<IQueryable<FileByTagQuery>> GetFilesByTagQuery(Guid tagOwner, TagType tagType, FilesDbContext filesDbContext)
{
IQueryable<FileByTagQuery> query;

var tenantId = await _tenantManager.GetCurrentTenantIdAsync();

var initQuery = filesDbContext.Files
.Where(x => x.TenantId == tenantId && x.CurrentVersion)
var initQuery = filesDbContext.Tag
.Where(x => x.TenantId == tenantId && x.Owner == tagOwner && x.Type == tagType)
.Join(filesDbContext.TagLink,
f => new
t => new
{
tenantId,
entryId = f.Id.ToString(),
entryType = FileEntryType.File
},
t.TenantId,
TagId = t.Id
},
l => new
{
tenantId = l.TenantId,
entryId = l.EntryId,
entryType = l.EntryType
l.TenantId,
l.TagId
},
(f, l) => new { f, l })
.Join(filesDbContext.Tag,
x => x.l.TagId,
t => t.Id,
(x, t) => new { x.f, x.l, t })
.Where(x => x.t.Type == tagType);

if (tagOwner.HasValue)
{
initQuery = initQuery.Where(x => x.t.Owner == tagOwner.Value);
}
(t, l) => new { t, l })
.Where(x => x.l.EntryType == FileEntryType.File)
.Join(filesDbContext.Files,
x => Convert.ToInt32(x.l.EntryId),
f => f.Id,
(x, f) => new { f, x.l, x.t })
.Where(x => x.f.CurrentVersion);

if (tagType == TagType.RecentByLink)
{
query = initQuery.Join(filesDbContext.Security,
x => new
x => new
{
tenantId,
entryId = x.f.Id.ToString(),
entryType = FileEntryType.File,
entryId = x.l.EntryId,
entryType = x.l.EntryType,
subject = x.t.Name
},
s => new
Expand Down
9 changes: 7 additions & 2 deletions products/ASC.Files/Core/Core/Security/FileSecurity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -910,9 +910,14 @@ private async Task<bool> FilterEntryAsync<T>(FileEntry<T> e, FilesSecurityAction
return false;
}

if (folder.FolderType == FolderType.Recent && isGuest)
if (folder.FolderType == FolderType.Recent)
{
return false;
if (isGuest)
{
return false;
}

return action == FilesSecurityActions.Read;
}

if (userId.Equals(ASC.Core.Configuration.Constants.Guest.ID) &&
Expand Down
4 changes: 2 additions & 2 deletions products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFileDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,13 +756,13 @@ public Task InitCustomOrder(Dictionary<string, int> fileIds, string parentFolder
return Task.CompletedTask;
}

public IAsyncEnumerable<File<string>> GetFilesByTagAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
public IAsyncEnumerable<File<string>> GetFilesByTagAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject, OrderBy orderBy, int offset = 0, int count = -1)
{
return AsyncEnumerable.Empty<File<string>>();
}

public Task<int> GetFilesByTagCountAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
public Task<int> GetFilesByTagCountAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject)
{
return default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,13 @@ public Task<int> GetFoldersCountAsync(string parentId, FilterType filterType, bo
throw new NotImplementedException();
}

public IAsyncEnumerable<File<string>> GetFilesByTagAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
public IAsyncEnumerable<File<string>> GetFilesByTagAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject, OrderBy orderBy, int offset = 0, int count = -1)
{
return AsyncEnumerable.Empty<File<string>>();
}

public Task<int> GetFilesByTagCountAsync(Guid? tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
public Task<int> GetFilesByTagCountAsync(Guid tagOwner, TagType tagType, FilterType filterType, bool subjectGroup, Guid subjectId,
string searchText, string[] extension, bool searchInContent, bool excludeSubject)
{
return default;
Expand Down

0 comments on commit 5d2ec3a

Please sign in to comment.