Skip to content

Commit

Permalink
Fixes tracking and inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Sep 3, 2023
1 parent bddc88f commit fb789f7
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public Task TrackAsync(DateOnly date, string key, string? category, Counters cou
category = GetCategory(category);

#pragma warning disable MA0105 // Use the lambda parameters instead of using a closure
jobs.AddOrUpdate((key, category, date), counters, (k, p) => p.SumUp(counters));
jobs.AddOrUpdate((key, category, date), counters, (k, p) => p.SumpUpCloned(counters));
#pragma warning restore MA0105 // Use the lambda parameters instead of using a closure

return Task.CompletedTask;
Expand Down Expand Up @@ -191,7 +191,7 @@ public async Task<Counters> GetAsync(string key, DateOnly fromDate, DateOnly toD

foreach (var usage in queried)
{
result.SumUp(usage.Counters);
result.SumpUp(usage.Counters);
}

return result;
Expand Down
15 changes: 11 additions & 4 deletions backend/src/Squidex.Infrastructure/UsageTracking/Counters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,22 @@ public long GetInt64(string name)
return (long)value;
}

public Counters SumUp(Counters counters)
public Counters SumpUpCloned(Counters counters)
{
foreach (var (key, value) in counters)
var result = new Counters(this);

return result.SumpUp(counters);
}

public Counters SumpUp(Counters source)
{
foreach (var (key, value) in source)
{
var newValue = value;

if (TryGetValue(key, out var temp))
if (TryGetValue(key, out var existing))
{
newValue += temp;
newValue += existing;
}

this[key] = newValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,40 @@ public async Task Should_write_usage_in_batches()
.MustHaveHappened();
}

[Fact]
public async Task Should_write_with_shared_counters()
{
var key1 = Guid.NewGuid().ToString();
var key2 = Guid.NewGuid().ToString();

var counters1 = Counters(a: 1, b: 2);

await sut.TrackAsync(date, key1, "my-category", counters1, ct);
await sut.TrackAsync(date, key2, "my-category", counters1, ct);

await sut.TrackAsync(date, key2, "my-category", Counters(a: 0.3, b: 2000), ct);

UsageUpdate[]? updates = null;

A.CallTo(() => usageStore.TrackUsagesAsync(A<UsageUpdate[]>._, A<CancellationToken>._))
.Invokes(args =>
{
updates = args.GetArgument<UsageUpdate[]>(0)!;
});

// Wait for the timer to trigger.
await WaitForCompletion();

updates.Should().BeEquivalentTo(new[]
{
new UsageUpdate(date, key1, "my-category", Counters(a: 1.0, b: 2)),
new UsageUpdate(date, key2, "my-category", Counters(a: 1.3, b: 2002)),
}, o => o.ComparingByMembers<UsageUpdate>());

A.CallTo(() => usageStore.TrackUsagesAsync(A<UsageUpdate[]>._, A<CancellationToken>._))
.MustHaveHappened();
}

private async Task WaitForCompletion()
{
sut.Next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<sqx-geolocation-editor [formControl]="$any(fieldForm)"></sqx-geolocation-editor>
</ng-container>
<ng-container *ngSwitchCase="'Json'">
<sqx-code-editor [formControl]="$any(fieldForm)" valueMode="Json" height="350"></sqx-code-editor>
<sqx-code-editor [formControl]="$any(fieldForm)" valueMode="Json" [height]="350"></sqx-code-editor>
</ng-container>
<ng-container *ngSwitchCase="'Number'">
<ng-container [ngSwitch]="field.rawProperties.editor">
Expand Down Expand Up @@ -195,7 +195,7 @@
</sqx-rich-editor>
</ng-container>
<ng-container *ngSwitchCase="'Html'">
<sqx-code-editor [formControl]="$any(fieldForm)" #editor mode="ace/mode/html" height="350" ></sqx-code-editor>
<sqx-code-editor [formControl]="$any(fieldForm)" #editor mode="ace/mode/html" [height]="350" ></sqx-code-editor>
</ng-container>
<ng-container *ngSwitchCase="'Markdown'">
<sqx-markdown-editor [formControl]="$any(fieldForm)" #editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
</button>
</div>

<sqx-code-editor [completion]="editorCompletion" height="350" [mode]="editorMode" [snippets]="mode === 'Script'"></sqx-code-editor>
<sqx-code-editor [completion]="editorCompletion" [height]="350" [mode]="editorMode" [snippets]="mode === 'Script'"></sqx-code-editor>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</ng-template>
</ng-container>
<ng-container *ngSwitchCase="'Javascript'">
<sqx-code-editor [completion]="ruleCompletions | async" [formControlName]="property.name" height="350"></sqx-code-editor>
<sqx-code-editor [completion]="ruleCompletions | async" [formControlName]="property.name" [height]="350"></sqx-code-editor>
</ng-container>
<ng-container *ngSwitchCase="'Checkbox'">
<div class="form-check">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="form-group">
<label>{{ 'schemas.field.graphQLSchema' | sqxTranslate }}</label>

<sqx-code-editor formControlName="graphQLSchema" mode="ace/mode/graphqlschema" height="350"></sqx-code-editor>
<sqx-code-editor formControlName="graphQLSchema" mode="ace/mode/graphqlschema" [height]="350"></sqx-code-editor>

<sqx-form-hint>
{{ 'schemas.field.graphQLSchemaHint' | sqxTranslate }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
{{ 'common.hide' | sqxTranslate }}
</button>

<sqx-code-editor height="250" *ngIf="showImport" formControlName="importing" valueMode="Json"></sqx-code-editor>
<sqx-code-editor [height]="250" *ngIf="showImport" formControlName="importing" valueMode="Json"></sqx-code-editor>
</div>
</ng-container>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class CodeEditorComponent extends StatefulControlComponent<{}, any> imple
@Input({ transform: booleanAttribute })
public wordWrap = false;

@Input({ transform: numberAttribute })
@Input()
public height: number | 'auto' | 'full' = 'full';

@Input({ transform: booleanAttribute })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export class FormAlertComponent {
public class = '';

@Input({ transform: numberAttribute })
public marginTop: number | string | undefined | null = 2;
public marginTop: number | undefined | null = 2;

@Input({ transform: numberAttribute })
public marginBottom: number | string | undefined | null = 4;
public marginBottom: number | undefined | null = 4;

@Input({ transform: booleanAttribute })
public light?: boolean | null;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/shared/components/tour-hint.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class TourHintDirective extends ResourceOwner implements OnDestroy, OnIni
public hintText!: string;

@Input({ transform: numberAttribute })
public hintAfter: number | string = 1000;
public hintAfter: number = 1000;

@Input()
public hintPosition?: FloatingPlacement;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/theme/_lists.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
thead {
// Small font size for the table header, content is more important!
th {
background: none;
border: 0;
color: $color-text-decent;
font-size: .8rem;
Expand Down

0 comments on commit fb789f7

Please sign in to comment.