private async ValueTask <IReadOnlyList <TenantSliceGroup <TDoc, TId> > > groupByConjoinedTenancy(IQuerySession querySession, List <IEvent> events)
        {
            var byTenant = events.GroupBy(x => x.TenantId);

            var groupTasks = byTenant.Select(async tGroup =>
            {
                var tenant = new Tenant(tGroup.Key, querySession.Database);

                var tenantSession = querySession.ForTenant(tGroup.Key);
                var group         = new TenantSliceGroup <TDoc, TId>(tenant);

                await GroupEvents(@group, tenantSession, tGroup.ToList()).ConfigureAwait(false);

                return(@group);
            });

            var list = new List <TenantSliceGroup <TDoc, TId> >();

            foreach (var groupTask in groupTasks)
            {
                list.Add(await groupTask.ConfigureAwait(false));
            }

            return(list);
        }
Exemple #2
0
        public async ValueTask <IReadOnlyList <TenantSliceGroup <TDoc, TId> > > SliceAsyncEvents(IQuerySession querySession, List <IEvent> events)
        {
            foreach (var fanOutRule in _beforeGroupingFanoutRules)
            {
                fanOutRule.Apply(events);
            }

            if (_groupByTenant)
            {
                var byTenant   = events.GroupBy(x => x.TenantId);
                var groupTasks = byTenant.Select(async tGroup =>
                {
                    var tenant = new Tenant(tGroup.Key, querySession.Database);
                    return(await groupSingleTenant(tenant, querySession.ForTenant(tGroup.Key), tGroup.ToList()).ConfigureAwait(false));
                });

                var list = new List <TenantSliceGroup <TDoc, TId> >();
                foreach (var groupTask in groupTasks)
                {
                    list.Add(await groupTask.ConfigureAwait(false));
                }

                return(list);
            }

            // This path is for *NOT* conjoined multi-tenanted projections, but we have to respect per-database tenancy
            var group = await groupSingleTenant(new Tenant(Tenancy.DefaultTenantId, querySession.Database), querySession, events).ConfigureAwait(false);

            return(new List <TenantSliceGroup <TDoc, TId> > {
                group
            });
        }
Exemple #3
0
        async ValueTask <IReadOnlyList <TenantSliceGroup <TDoc, TId> > > IEventSlicer <TDoc, TId> .SliceAsyncEvents(
            IQuerySession querySession,
            List <IEvent> events, ITenancy tenancy)
        {
            foreach (var fanOutRule in _beforeGroupingFanoutRules)
            {
                fanOutRule.Apply(events);
            }

            if (_groupByTenant)
            {
                var byTenant   = events.GroupBy(x => x.TenantId);
                var groupTasks = byTenant.Select(tGroup =>
                {
                    var tenant = tenancy[tGroup.Key];
                    return(groupSingleTenant(tenant, querySession.ForTenant(tGroup.Key), tGroup.ToList()));
                });

                var list = new List <TenantSliceGroup <TDoc, TId> >();
                foreach (var groupTask in groupTasks)
                {
                    list.Add(await groupTask);
                }

                return(list);
            }

            var group = await groupSingleTenant(tenancy.Default, querySession, events);



            return(new List <TenantSliceGroup <TDoc, TId> > {
                group
            });
        }