Browse Source

Indexer fixed.

pull/419/head
Sebastian Stehle 7 years ago
parent
commit
657d3435af
  1. 1
      src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs
  2. 1
      src/Squidex/Areas/Api/Controllers/Apps/AppsController.cs
  3. 92
      tools/Migrate_01/Migrations/PopulateGrainIndexes.cs

1
src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs

@ -8,7 +8,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Orleans;
using Squidex.Domain.Apps.Entities.Apps.Indexes; using Squidex.Domain.Apps.Entities.Apps.Indexes;
using Squidex.Domain.Apps.Entities.Backup; using Squidex.Domain.Apps.Entities.Backup;
using Squidex.Domain.Apps.Events; using Squidex.Domain.Apps.Events;

1
src/Squidex/Areas/Api/Controllers/Apps/AppsController.cs

@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
using NSwag.Annotations; using NSwag.Annotations;
using Squidex.Areas.Api.Controllers.Apps.Models; using Squidex.Areas.Api.Controllers.Apps.Models;
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Entities; using Squidex.Domain.Apps.Entities;
using Squidex.Domain.Apps.Entities.Apps; using Squidex.Domain.Apps.Entities.Apps;
using Squidex.Domain.Apps.Entities.Apps.Commands; using Squidex.Domain.Apps.Entities.Apps.Commands;

92
tools/Migrate_01/Migrations/PopulateGrainIndexes.cs

@ -9,14 +9,14 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Squidex.Domain.Apps.Entities.Apps.Indexes; using Squidex.Domain.Apps.Entities.Apps.Indexes;
using Squidex.Domain.Apps.Entities.Apps.State;
using Squidex.Domain.Apps.Entities.Rules.Indexes; using Squidex.Domain.Apps.Entities.Rules.Indexes;
using Squidex.Domain.Apps.Entities.Rules.State;
using Squidex.Domain.Apps.Entities.Schemas.Indexes; using Squidex.Domain.Apps.Entities.Schemas.Indexes;
using Squidex.Domain.Apps.Entities.Schemas.State; using Squidex.Domain.Apps.Events.Apps;
using Squidex.Domain.Apps.Events.Rules;
using Squidex.Domain.Apps.Events.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.EventSourcing;
using Squidex.Infrastructure.Migrations; using Squidex.Infrastructure.Migrations;
using Squidex.Infrastructure.States;
using Squidex.Infrastructure.Tasks; using Squidex.Infrastructure.Tasks;
namespace Migrate_01.Migrations namespace Migrate_01.Migrations
@ -26,29 +26,26 @@ namespace Migrate_01.Migrations
private readonly IAppsIndex indexApps; private readonly IAppsIndex indexApps;
private readonly IRulesIndex indexRules; private readonly IRulesIndex indexRules;
private readonly ISchemasIndex indexSchemas; private readonly ISchemasIndex indexSchemas;
private readonly ISnapshotStore<AppState, Guid> statesForApps; private readonly IEventDataFormatter eventDataFormatter;
private readonly ISnapshotStore<RuleState, Guid> statesForRules; private readonly IEventStore eventStore;
private readonly ISnapshotStore<SchemaState, Guid> statesForSchemas;
public PopulateGrainIndexes( public PopulateGrainIndexes(
IAppsIndex indexApps, IAppsIndex indexApps,
IRulesIndex indexRules, IRulesIndex indexRules,
ISchemasIndex indexSchemas, ISchemasIndex indexSchemas,
ISnapshotStore<AppState, Guid> statesForApps, IEventDataFormatter eventDataFormatter,
ISnapshotStore<RuleState, Guid> statesForRules, IEventStore eventStore)
ISnapshotStore<SchemaState, Guid> statesForSchemas)
{ {
this.indexApps = indexApps; this.indexApps = indexApps;
this.indexRules = indexRules; this.indexRules = indexRules;
this.indexSchemas = indexSchemas; this.indexSchemas = indexSchemas;
this.statesForApps = statesForApps; this.eventDataFormatter = eventDataFormatter;
this.statesForRules = statesForRules; this.eventStore = eventStore;
this.statesForSchemas = statesForSchemas;
} }
public Task UpdateAsync() public async Task UpdateAsync()
{ {
return Task.WhenAll( await Task.WhenAll(
RebuildAppIndexes(), RebuildAppIndexes(),
RebuildRuleIndexes(), RebuildRuleIndexes(),
RebuildSchemaIndexes()); RebuildSchemaIndexes());
@ -59,20 +56,35 @@ namespace Migrate_01.Migrations
var appsByName = new Dictionary<string, Guid>(); var appsByName = new Dictionary<string, Guid>();
var appsByUser = new Dictionary<string, HashSet<Guid>>(); var appsByUser = new Dictionary<string, HashSet<Guid>>();
await statesForApps.ReadAllAsync((app, version) => await eventStore.QueryAsync(storedEvent =>
{ {
if (!app.IsArchived) var @event = eventDataFormatter.Parse(storedEvent.Data);
{
appsByName[app.Name] = app.Id;
foreach (var contributor in app.Contributors.Keys) switch (@event.Payload)
{ {
appsByUser.GetOrAddNew(contributor).Add(app.Id); case AppCreated appCreated:
} appsByName[appCreated.Name] = appCreated.AppId.Id;
break;
case AppContributorAssigned appContributorAssigned:
appsByUser.GetOrAddNew(appContributorAssigned.ContributorId).Add(appContributorAssigned.AppId.Id);
break;
case AppContributorRemoved contributorRemoved:
appsByUser.GetOrAddNew(contributorRemoved.ContributorId).Remove(contributorRemoved.AppId.Id);
break;
case AppArchived appArchived:
{
foreach (var apps in appsByUser.Values)
{
apps.Remove(appArchived.AppId.Id);
}
appsByName.Remove(appArchived.AppId.Name);
break;
}
} }
return TaskHelper.Done; return TaskHelper.Done;
}); }, "^app\\-");
await indexApps.RebuildAsync(appsByName); await indexApps.RebuildAsync(appsByName);
@ -86,15 +98,22 @@ namespace Migrate_01.Migrations
{ {
var rulesByApp = new Dictionary<Guid, HashSet<Guid>>(); var rulesByApp = new Dictionary<Guid, HashSet<Guid>>();
await statesForRules.ReadAllAsync((rule, version) => await eventStore.QueryAsync(storedEvent =>
{ {
if (!rule.IsDeleted) var @event = eventDataFormatter.Parse(storedEvent.Data);
switch (@event.Payload)
{ {
rulesByApp.GetOrAddNew(rule.AppId.Id).Add(rule.Id); case RuleCreated ruleCreated:
rulesByApp.GetOrAddNew(ruleCreated.AppId.Id).Add(ruleCreated.RuleId);
break;
case RuleDeleted ruleDeleted:
rulesByApp.GetOrAddNew(ruleDeleted.AppId.Id).Remove(ruleDeleted.RuleId);
break;
} }
return TaskHelper.Done; return TaskHelper.Done;
}); }, "^rule\\-");
foreach (var kvp in rulesByApp) foreach (var kvp in rulesByApp)
{ {
@ -106,15 +125,22 @@ namespace Migrate_01.Migrations
{ {
var schemasByApp = new Dictionary<Guid, Dictionary<string, Guid>>(); var schemasByApp = new Dictionary<Guid, Dictionary<string, Guid>>();
await statesForSchemas.ReadAllAsync((schema, version) => await eventStore.QueryAsync(storedEvent =>
{ {
if (!schema.IsDeleted) var @event = eventDataFormatter.Parse(storedEvent.Data);
switch (@event.Payload)
{ {
schemasByApp.GetOrAddNew(schema.AppId.Id)[schema.SchemaDef.Name] = schema.Id; case SchemaCreated schemaCreated:
schemasByApp.GetOrAddNew(schemaCreated.AppId.Id)[schemaCreated.SchemaId.Name] = schemaCreated.SchemaId.Id;
break;
case SchemaDeleted schemaDeleted:
schemasByApp.GetOrAddNew(schemaDeleted.AppId.Id).Remove(schemaDeleted.SchemaId.Name);
break;
} }
return TaskHelper.Done; return TaskHelper.Done;
}); }, "^schema\\-");
foreach (var kvp in schemasByApp) foreach (var kvp in schemasByApp)
{ {
@ -122,4 +148,4 @@ namespace Migrate_01.Migrations
} }
} }
} }
} }
Loading…
Cancel
Save