-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove more json stuff + cache RepositoryAction files and env files f…
…or speeding up process.
- Loading branch information
Showing
28 changed files
with
232 additions
and
292 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...i/IO/ModuleBasedRepositoryActionProvider/Deserialization/IRepositoryActionDeserializer.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,8 @@ | ||
namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; | ||
|
||
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; | ||
|
||
public interface IRepositoryActionDeserializer | ||
{ | ||
RepositoryActionConfiguration Deserialize(string content); | ||
} |
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
16 changes: 8 additions & 8 deletions
16
...eBasedRepositoryActionProvider/Deserialization/YamlDynamicRepositoryActionDeserializer.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
75 changes: 75 additions & 0 deletions
75
src/RepoM.Api/IO/ModuleBasedRepositoryActionProvider/RepositoryActionsFileStore.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,75 @@ | ||
namespace RepoM.Api.IO.ModuleBasedRepositoryActionProvider; | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO.Abstractions; | ||
using System.Runtime.Caching; | ||
using DotNetEnv; | ||
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Data; | ||
using RepoM.Api.IO.ModuleBasedRepositoryActionProvider.Deserialization; | ||
|
||
internal class RepositoryActionsFileStore | ||
{ | ||
private readonly IFileSystem _fileSystem; | ||
private readonly IRepositoryActionDeserializer _repositoryActionsDeserializer; | ||
private readonly ObjectCache _cache; | ||
|
||
public RepositoryActionsFileStore(IFileSystem fileSystem, IRepositoryActionDeserializer repositoryActionsDeserializer, ObjectCache cache) | ||
{ | ||
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem)); | ||
_repositoryActionsDeserializer = repositoryActionsDeserializer ?? throw new ArgumentNullException(nameof(repositoryActionsDeserializer)); | ||
_cache = cache ?? throw new ArgumentNullException(nameof(cache)); | ||
} | ||
|
||
public RepositoryActionConfiguration? TryGet(string filename) | ||
{ | ||
if (_cache[filename] is RepositoryActionConfiguration fileContents) | ||
{ | ||
return fileContents; | ||
} | ||
|
||
var policy = new CacheItemPolicy(); | ||
var filePaths = new List<string>(1) { filename, }; | ||
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); | ||
|
||
var payload = _fileSystem.File.ReadAllText(filename); | ||
fileContents = _repositoryActionsDeserializer.Deserialize(payload); | ||
|
||
if (fileContents == null) | ||
{ | ||
return null; | ||
} | ||
|
||
var cacheResult = _cache.AddOrGetExisting(filename, fileContents, policy) as RepositoryActionConfiguration; | ||
return cacheResult ?? fileContents; | ||
} | ||
} | ||
|
||
internal class EnvFileStore | ||
{ | ||
private readonly ObjectCache _cache; | ||
|
||
public EnvFileStore(ObjectCache cache) | ||
{ | ||
_cache = cache ?? throw new ArgumentNullException(nameof(cache)); | ||
} | ||
|
||
public IDictionary<string, string> TryGet(string filename) | ||
{ | ||
if (_cache[filename] is Dictionary<string, string> fileContents) | ||
{ | ||
return fileContents; | ||
} | ||
|
||
var policy = new CacheItemPolicy(); | ||
var filePaths = new List<string>(1) { filename, }; | ||
policy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths)); | ||
|
||
IEnumerable<KeyValuePair<string, string>>? result = Env.Load(filename, new LoadOptions(setEnvVars: false)); | ||
|
||
fileContents = result == null ? new Dictionary<string, string>(0) : result.ToDictionary(); | ||
|
||
var cacheResult = _cache.AddOrGetExisting(filename, fileContents, policy) as Dictionary<string, string>; | ||
return cacheResult ?? fileContents; | ||
} | ||
} |
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.