Sumanth Shendye
Sumanth Shendye

Reputation: 15

What the way to query the reliable collection(IReliableDictionary) in Service Fabric?

we have scenario where reliable dictionary holds around 100000 records, each record contains bool property indicates whether its active or inactive record. i need to fetch only active record from the collection.

I used below method

IReliableDictionary<string, AlertEntity> storeAlert = await this.stateManager.GetOrAddAsync<IReliableDictionary<string, AlertEntity>>(TargetSolution.Names.AlertsRegistryStore);
using (ITransaction tx = this.stateManager.CreateTransaction())
{
                IAsyncEnumerable<KeyValuePair<string, AlertEntity>> enumerable = await storeAlert.CreateEnumerableAsync(tx, EnumerationMode.Ordered);
                IAsyncEnumerator<KeyValuePair<string, AlertEntity>> enumerator = enumerable.GetAsyncEnumerator();
                while (await enumerator.MoveNextAsync(appLifetime.ApplicationStopping))
                {
                    if (enumerator.Current.Value.ISActive)
                    {
                        alerts.Add(enumerator.Current.Value);
                    }
                }
                await tx.CommitAsync();
}

As per my understanding above code iterates each record to identify the IsActive property to true which i feel is time consuming.

So is There Any way to optimize this code using filter or LINQ query?

Can anybody help!!!!

Thanks for your Response :)

Upvotes: 0

Views: 126

Answers (0)

Related Questions