Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test results #205

Merged
merged 5 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Tql.Abstractions/ICache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ public interface ICache<T>
/// </summary>
/// <returns>Current version of the cache.</returns>
Task<T> Get();

/// <summary>
/// Raises the <see cref="Updated"/> event.
/// </summary>
/// <remarks>
/// This can be used to simulate a cache update without actually
/// updating the cache. The primary use case for this is to reload
/// cached matches if the <c>IconCacheManager</c> completes loading
/// an image.
/// </remarks>
void RaiseUpdated();
}
4 changes: 2 additions & 2 deletions src/Tql.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ private void CacheManagerManager_CacheChanged(object? sender, EventArgs e)
void Invoke()
{
if (IsVisible)
SearchManager?.DoSearch();
SearchManager?.DoSearch(true);
}
}

Expand Down Expand Up @@ -443,7 +443,7 @@ private void _searchManager_SearchCompleted(object? sender, SearchResultsEventAr

_results.ItemsSource = e.Results;

if (_results.Items.Count > 0)
if (!e.IsUpdated && _results.Items.Count > 0)
{
SetSelectedIndex(0);

Expand Down
2 changes: 1 addition & 1 deletion src/Tql.App/QuickStart/Playbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ window.
Search results are identified by the ![](Person+Running.svg?color=true) icon,
and categories by the ![](Apps+List.svg?color=true) icon.

![](Keyboard.svg?color=true) Press ::Tab:: to enter the lighlighted category.
![](Keyboard.svg?color=true) Press ::Tab:: to enter the highlighted category.

---
id: search-hint-jira
Expand Down
6 changes: 3 additions & 3 deletions src/Tql.App/Search/SearchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void ReloadHistory()
LoadHistory();
}

public async void DoSearch()
public async void DoSearch(bool isUpdate = false)
{
if (_suspendSearch > 0)
return;
Expand Down Expand Up @@ -230,7 +230,7 @@ public async void DoSearch()

results ??= ImmutableArray<SearchResult>.Empty;

OnSearchCompleted(new SearchResultsEventArgs(results.Value, false));
OnSearchCompleted(new SearchResultsEventArgs(results.Value, false, isUpdate));

telemetry.AddProperty("Results", results.Value.Length.ToString());
telemetry.IsSuccess = true;
Expand Down Expand Up @@ -425,7 +425,7 @@ private async Task ShowPreliminaryResults()
{
var results = await GetPreliminaryResults();
if (results != null)
OnSearchCompleted(new SearchResultsEventArgs(results.Value, true));
OnSearchCompleted(new SearchResultsEventArgs(results.Value, true, false));
}

private async Task<ImmutableArray<SearchResult>?> GetPreliminaryResults()
Expand Down
8 changes: 6 additions & 2 deletions src/Tql.App/Search/SearchResultsEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace Tql.App.Search;

internal class SearchResultsEventArgs(ImmutableArray<SearchResult> results, bool isPreliminary)
: EventArgs
internal class SearchResultsEventArgs(
ImmutableArray<SearchResult> results,
bool isPreliminary,
bool isUpdate
) : EventArgs
{
public ImmutableArray<SearchResult> Results { get; } = results;
public bool IsPreliminary { get; } = isPreliminary;
public bool IsUpdated { get; } = isUpdate;
}
43 changes: 31 additions & 12 deletions src/Tql.App/Services/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,16 @@ private void Create(bool initialLoad)
raiseCacheChanged = true;
}

ThreadPool.QueueUserWorkItem(_ =>
{
_logger.LogInformation("Raising cache updated");
_logger.LogInformation("Raising cache updated");

try
{
OnUpdated(new CacheEventArgs<T>(data));
}
catch (Exception ex)
{
_logger.LogError(ex, "Raising cache updated failed");
}
});
try
{
OnUpdated(new CacheEventArgs<T>(data));
}
catch (Exception ex)
{
_logger.LogError(ex, "Raising cache updated failed");
}

telemetry.IsSuccess = true;
}
Expand Down Expand Up @@ -261,4 +258,26 @@ public Task<T> Get()
}

protected virtual void OnUpdated(CacheEventArgs<T> e) => Updated?.Invoke(this, e);

public void RaiseUpdated()
{
// We don't raise the events if the cache isn't available.

var task = _tcs.Task;
if (!task.IsCompleted)
return;

_logger.LogInformation("Raising cache updated");

try
{
OnUpdated(new CacheEventArgs<T>(task.Result));
}
catch (Exception ex)
{
_logger.LogError(ex, "Raising cache updated failed");
}

_cacheManagerManager.RaiseCacheChanged();
}
}
9 changes: 9 additions & 0 deletions src/Tql.Plugins.Confluence/Services/IconCacheManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.Extensions.Logging;
using Tql.Abstractions;
using Tql.Plugins.Confluence.Data;
using Tql.Utilities;

namespace Tql.Plugins.Confluence.Services;

internal class IconCacheManager(
IStore store,
ILogger<IconCacheManager> logger,
ICache<ConfluenceData> cache,
ConfigurationManager configurationManager
)
: IconCacheManager<IconKey>(
Expand All @@ -32,6 +34,13 @@ protected override Task<IconData> LoadIcon(IconKey key)
}
);
}

protected override void OnIconLoaded()
{
base.OnIconLoaded();

cache.RaiseUpdated();
}
}

internal record IconKey(string ConnectionUrl, string Url);
9 changes: 9 additions & 0 deletions src/Tql.Plugins.Jira/Services/IconCacheManager.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Microsoft.Extensions.Logging;
using Tql.Abstractions;
using Tql.Plugins.Jira.Data;
using Tql.Utilities;

namespace Tql.Plugins.Jira.Services;

internal class IconCacheManager(
IStore store,
ILogger<IconCacheManager> logger,
ICache<JiraData> cache,
ConfigurationManager configurationManager
)
: IconCacheManager<IconKey>(
Expand All @@ -32,6 +34,13 @@ protected override Task<IconData> LoadIcon(IconKey key)
}
);
}

protected override void OnIconLoaded()
{
base.OnIconLoaded();

cache.RaiseUpdated();
}
}

internal record IconKey(string ConnectionUrl, string Url);
5 changes: 5 additions & 0 deletions tests/Tql.PluginTestSupport/Services/TestCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@ private void Create()

public Task<T> Get() => Task.FromResult(_data);

public void RaiseUpdated()
{
OnUpdated(new CacheEventArgs<T>(_data));
}

protected virtual void OnUpdated(CacheEventArgs<T> e) => Updated?.Invoke(this, e);
}
Loading