-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New mechanism for gettings user visible spaces (#52)
* Add flat permissions contract and extend methods for use this permissions * Use new functional for search spaces with permissions * Remove caching all space list
- Loading branch information
Showing
10 changed files
with
188 additions
and
130 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/Mimisbrunnr.Storage.MongoDb/Migrations/SpacesFlatPermissionMigrationModule.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Mimisbrunnr.Wiki.Contracts; | ||
using Skidbladnir.Modules; | ||
using Skidbladnir.Repository.Abstractions; | ||
|
||
namespace Mimisbrunnr.Storage.MongoDb.Migrations | ||
{ | ||
public class SpacesFlatPermissionMigrationModule : BackgroundModule | ||
{ | ||
private const int BatchSize = 100; | ||
|
||
public override async Task ExecuteAsync(IServiceProvider provider, CancellationToken cancellationToken = default) | ||
{ | ||
var logger = provider.GetService<ILogger<SpacesFlatPermissionMigrationModule>>(); | ||
var spaceRepository = provider.GetService<IRepository<Space>>(); | ||
|
||
logger.LogInformation("Permissions migration started"); | ||
|
||
var page = 0; | ||
var spaces = await GetBatch(spaceRepository, page++); | ||
while (spaces.Length > 0) | ||
{ | ||
foreach( var space in spaces){ | ||
var previousCount = space.PermissionsFlat == null ? 0 : space.PermissionsFlat.Length; | ||
space.UpdatePermissions(); | ||
if(previousCount != space.PermissionsFlat.Length) | ||
await spaceRepository.Update(space); | ||
} | ||
spaces = await GetBatch(spaceRepository, page++); | ||
} | ||
logger.LogInformation("Permissions migration completed"); | ||
|
||
} | ||
|
||
private static async Task<Space[]> GetBatch(IRepository<Space> repository, int page) | ||
{ | ||
return await repository.GetAll().Take(BatchSize).Skip(BatchSize * page).ToArrayAsync(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
using Mimisbrunnr.Wiki.Contracts; | ||
|
||
namespace Mimisbrunnr.Web.Services; | ||
|
||
public interface ISpaceDisplayService | ||
{ | ||
Task<IEnumerable<Space>> FindUserVisibleSpaces(UserInfo userInfo); | ||
using Mimisbrunnr.Wiki.Contracts; | ||
|
||
namespace Mimisbrunnr.Web.Services; | ||
|
||
public interface ISpaceDisplayService | ||
{ | ||
Task<IEnumerable<Space>> FindUserVisibleSpaces(UserInfo userInfo, int? take = null, int? skip = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.