Skip to content

Commit

Permalink
Avoid unnecessary calls to Storage APIs (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
manodasanW authored Apr 16, 2023
1 parent 2f050b3 commit d93dd81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/GithubPlugin/DataManager/GitHubDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public partial class GitHubDataManager : IGitHubDataManager, IDisposable

public static IGitHubDataManager? CreateInstance(DataStoreOptions? options = null)
{
options ??= DefaultOptions();
options ??= DefaultOptions;

try
{
Expand Down Expand Up @@ -640,7 +640,13 @@ private void ValidateDataStore()
}
}

private static DataStoreOptions DefaultOptions()
// Making the default options a singleton to avoid repeatedly calling the storage APIs and
// creating a new GitHubDataStoreSchema when not necessary.
private static readonly Lazy<DataStoreOptions> LazyDataStoreOptions = new (DefaultOptionsInit);

private static DataStoreOptions DefaultOptions => LazyDataStoreOptions.Value;

private static DataStoreOptions DefaultOptionsInit()
{
return new DataStoreOptions
{
Expand Down
2 changes: 1 addition & 1 deletion src/GithubPlugin/Widgets/GithubWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ protected string GetTemplateForPage(WidgetPageState page)

try
{
var path = Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, GetTemplatePath(page));
var path = Path.Combine(AppContext.BaseDirectory, GetTemplatePath(page));
var template = File.ReadAllText(path, Encoding.Default) ?? throw new FileNotFoundException(path);
template = Resources.ReplaceIdentifers(template, Resources.GetWidgetResourceIdentifiers(), Log.Logger());
Log.Logger()?.ReportDebug(Name, ShortId, $"Caching template for {page}");
Expand Down

0 comments on commit d93dd81

Please sign in to comment.