Skip to content

Commit

Permalink
- New index in storage
Browse files Browse the repository at this point in the history
- Avoid caching when migrating texts
- Make a2 websa html inline in browser
- Send new instance event properties back to sbl via SblInstanceEvent
  • Loading branch information
Henning Normann committed Nov 29, 2024
1 parent 4b24464 commit a0a592a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/Storage/Controllers/MigrationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc;

using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
Expand Down Expand Up @@ -51,6 +51,7 @@ public class MigrationController : ControllerBase
private readonly GeneralSettings _generalSettings;
private readonly AzureStorageConfiguration _azureStorageSettings;
private readonly HttpClient _httpClient;
private readonly IMemoryCache _memoryCache;

/// <summary>
/// Initializes a new instance of the <see cref="MigrationController"/> class
Expand All @@ -67,6 +68,7 @@ public class MigrationController : ControllerBase
/// <param name="azureStorageSettings">the azureStorage settings.</param>
/// <param name="generalSettings">Settings with endpoint uri</param>
/// <param name="httpClient">The HttpClient to use in communication with the PDF generator service.</param>
/// <param name="memoryCache">the memory cache</param>
public MigrationController(

Check warning on line 72 in src/Storage/Controllers/MigrationController.cs

View workflow job for this annotation

GitHub Actions / Build, test & analyze

Constructor has 13 parameters, which is greater than the 7 authorized. (https://rules.sonarsource.com/csharp/RSPEC-107)
IInstanceRepository instanceRepository,
IInstanceEventRepository instanceEventRepository,
Expand All @@ -79,7 +81,8 @@ public MigrationController(
IOptions<GeneralSettings> settings,
IOptions<AzureStorageConfiguration> azureStorageSettings,
IOptions<GeneralSettings> generalSettings,
HttpClient httpClient)
HttpClient httpClient,
IMemoryCache memoryCache)
{
_instanceRepository = instanceRepository;
_instanceEventRepository = instanceEventRepository;
Expand All @@ -93,6 +96,7 @@ public MigrationController(
_azureStorageSettings = azureStorageSettings.Value;
_httpClient = httpClient;
_httpClient.BaseAddress = new Uri(generalSettings.Value.PdfGeneratorEndpoint);
_memoryCache = memoryCache;
}

/// <summary>
Expand Down Expand Up @@ -349,6 +353,12 @@ public async Task<ActionResult<Instance>> CreateText([FromRoute] string org, [Fr
{
try
{
string cacheKey = $"tid:{org}-{app}-{language}";
if (_memoryCache.Get(cacheKey) != null)
{
_memoryCache.Remove(cacheKey);
}

TextResource textResource = await _textRepository.Get(org, app, language);
using var reader = new StreamReader(Request.Body);
if (textResource == null)
Expand Down
4 changes: 3 additions & 1 deletion src/Storage/Helpers/InstanceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public static List<SblInstanceEvent> ConvertToSBLInstanceEvent(List<InstanceEven
Id = instanceEvent.Id,
User = instanceEvent.User,
CreatedDateTime = instanceEvent.Created,
EventType = instanceEvent.EventType
EventType = instanceEvent.EventType,
AdditionalInfo = instanceEvent.AdditionalInfo,
RelatedUser = instanceEvent.RelatedUser
});
}

Expand Down
14 changes: 13 additions & 1 deletion src/Storage/Helpers/SblInstanceEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@ public class SblInstanceEvent
/// </summary>
[JsonProperty(PropertyName = "user")]
public PlatformUser User { get; set; }


/// <summary>
/// A user that is related to the event
/// </summary>
[JsonProperty(PropertyName = "relatedUser")]
public PlatformUser RelatedUser { get; set; }

/// <summary>
/// Additional information describing the event
/// </summary>
[JsonProperty(PropertyName = "additionalInfo")]
public string AdditionalInfo { get; set; }

/// <inheritdoc/>
public override string ToString()
{
Expand Down
1 change: 1 addition & 0 deletions src/Storage/Migration/v0.16/01-create-index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX IF NOT EXISTS instances_org_lastchanged ON storage.instances(org, lastChanged);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This script is autogenerated from the tool DbTools. Do not edit manually.

0 comments on commit a0a592a

Please sign in to comment.