public async IAsyncEnumerable <TDataType> ReadIndex <TDataType, TKeyType>(TKeyType key, Expression <Func <TDataType, TKeyType> > indexProperty) where TDataType : DataEntity { var indexMember = ((MemberExpression)indexProperty.Body).Member; using (Logger.BeginScope("{Operation} is {Action} {IndexName} for {DataType} with a key {key}", nameof(DataManager), "read from index", indexMember.Name, typeof(TDataType).Name, key)) { if (indexMember.IsDefined(typeof(IndexAttribute), true)) { Logger.LogTrace("Property is indexed"); var indexName = indexMember.Name; if (await IndexWorker.IndexExist <TDataType>(indexName)) { Logger.LogTrace("Index exists"); var ids = IndexWorker.GetIdsFromIndex <TDataType, TKeyType>(indexName, key); Logger.LogInformation("Found ids in index", ids, key); await foreach (var id in ids) { yield return(await Read <TDataType>(id)); } } yield break; } Logger.LogWarning("The property used is not marked as indexed"); } }
public async IAsyncEnumerable <IndexKey <TKeyType> > ReadIndexKeys <TDataType, TKeyType>(Expression <Func <TDataType, TKeyType> > indexProperty) where TDataType : DataEntity { var indexMember = ((MemberExpression)indexProperty.Body).Member; using (Logger.BeginScope("{Operation} is {Action} {IndexName} for {DataType}", nameof(DataManager), "getting keys from index", indexMember.Name, typeof(TDataType).Name)) { if (indexMember.IsDefined(typeof(IndexAttribute), true)) { Logger.LogTrace("Property is indexed"); var indexName = indexMember.Name; if (await IndexWorker.IndexExist <TDataType>(indexName)) { var keys = IndexWorker.GetKeysFromIndex <TDataType, TKeyType>(indexName); Logger.LogInformation("Found keys in index", keys); await foreach (var key in keys) { yield return(key); } } yield break; } Logger.LogWarning("The property used is not marked as indexed"); } }