Skip to content

Commit

Permalink
Merge pull request #34 from AElfProject/release/1.2.0
Browse files Browse the repository at this point in the history
Release v1.2.0
  • Loading branch information
jason-aelf authored Sep 26, 2024
2 parents 2935bf8 + b7c640d commit a620ce3
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 860 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public override void ConfigureServices(ServiceConfigurationContext context)
services.AddTransient(typeof(IElasticsearchRepository<,>), typeof(ElasticsearchRepository<,>));
services.AddTransient(typeof(ICollectionNameProvider<>), typeof(ElasticsearchCollectionNameProvider<>));
services.AddSingleton(typeof (IShardingKeyProvider<>), typeof (ShardingKeyProvider<>));
services.AddSingleton(typeof(ICollectionRouteKeyProvider<>), typeof(CollectionRouteKeyProvider<>));
services.AddSingleton(typeof(IElasticsearchQueryableFactory<>), typeof(ElasticsearchQueryableFactory<>));
services.AddSingleton(typeof (IShardingCollectionTailProvider<>), typeof (ShardingCollectionTailProvider<>));
var configuration = context.Services.GetConfiguration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,16 @@ public class ElasticsearchCollectionNameProvider<TEntity> : CollectionNameProvid
{
private readonly IElasticIndexService _elasticIndexService;
private readonly IShardingKeyProvider<TEntity> _shardingKeyProvider;
private readonly ICollectionRouteKeyProvider<TEntity> _collectionRouteKeyProvider;
private readonly AElfEntityMappingOptions _entityMappingOptions;
private readonly ILogger<ElasticsearchCollectionNameProvider<TEntity>> _logger;

public ElasticsearchCollectionNameProvider(IShardingKeyProvider<TEntity> shardingKeyProvider,
IElasticIndexService elasticIndexService,
ICollectionRouteKeyProvider<TEntity> collectionRouteKeyProvider,
IOptions<AElfEntityMappingOptions> entityMappingOptions,
ILogger<ElasticsearchCollectionNameProvider<TEntity>> logger)
{
_elasticIndexService = elasticIndexService;
_shardingKeyProvider = shardingKeyProvider;
_collectionRouteKeyProvider = collectionRouteKeyProvider;
_entityMappingOptions = entityMappingOptions.Value;
_logger = logger;
}
Expand All @@ -42,7 +39,7 @@ protected override async Task<List<string>> GetCollectionNameAsync(List<Collecti
var shardKeyCollectionNames = await _shardingKeyProvider.GetCollectionNameAsync(conditions);
if (shardKeyCollectionNames.IsNullOrEmpty())
{
return await _collectionRouteKeyProvider.GetCollectionNameAsync(conditions);
return new List<string> { GetDefaultCollectionName() };
}

return shardKeyCollectionNames;
Expand Down Expand Up @@ -71,9 +68,7 @@ protected override async Task<List<string>> GetCollectionNameByEntityAsync(List<

protected override async Task<string> GetCollectionNameByIdAsync<TKey>(TKey id)

Check warning on line 69 in src/AElf.EntityMapping.Elasticsearch/ElasticsearchCollectionNameProvider.cs

View workflow job for this annotation

GitHub Actions / publish

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
if (!_shardingKeyProvider.IsShardingCollection())
return GetDefaultCollectionName();
return await _collectionRouteKeyProvider.GetCollectionNameAsync(id.ToString());
return GetDefaultCollectionName();
}

protected override string FormatCollectionName(string name)
Expand Down
7 changes: 0 additions & 7 deletions src/AElf.EntityMapping.Elasticsearch/IndexNameHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,4 @@ public static string GetDefaultFullIndexName(Type type,string collectionPrefix)
: $"{collectionPrefix.ToLower()}.{GetDefaultIndexName(type)}";
return fullIndexName;
}
public static string GetCollectionRouteKeyIndexName(Type type, string fieldName,string collectionPrefix)
{
var routeIndexName= collectionPrefix.IsNullOrWhiteSpace()
? $"route.{type.Name.ToLower()}.{fieldName.ToLower()}"
: $"{collectionPrefix.ToLower()}.route.{type.Name.ToLower()}.{fieldName.ToLower()}";
return routeIndexName;
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,6 @@ public async Task CreateIndexTemplateAsync(string indexTemplateName,string index
_logger.LogInformation("Index template {indexTemplateName} created successfully", indexTemplateName);
}
}

public async Task CreateCollectionRouteKeyIndexAsync(Type type, int shard = 1, int numberOfReplicas = 1)
{
var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (var property in properties)
{
CollectionRouteKeyAttribute shardRouteAttribute = (CollectionRouteKeyAttribute)Attribute.GetCustomAttribute(property, typeof(CollectionRouteKeyAttribute));
if (shardRouteAttribute != null)
{
if (property.PropertyType != typeof(string))
{
throw new NotSupportedException(
$"{type.Name} Attribute Error! NeedShardRouteAttribute only support string type, please check field: {property.Name}");
}
var indexName = IndexNameHelper.GetCollectionRouteKeyIndexName(type, property.Name,_entityMappingOptions.CollectionPrefix);
await CreateIndexAsync(indexName, typeof(RouteKeyCollection), shard, numberOfReplicas);
}
}
}

public async Task DeleteIndexAsync(string collectionName = null, CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ private async Task HandleModuleAsync(Type moduleType)
await _elasticIndexService.CreateIndexTemplateAsync(indexTemplateName, indexName, t,
_elasticsearchOptions.NumberOfShards,
_elasticsearchOptions.NumberOfReplicas);
//create index marked field cache
// await _elasticIndexService.InitializeCollectionRouteKeyCacheAsync(t);
//create non shard key route index
await _elasticIndexService.CreateCollectionRouteKeyIndexAsync(t, _elasticsearchOptions.NumberOfShards,
_elasticsearchOptions.NumberOfReplicas);
await CreateShardingCollectionTailIndexAsync();
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ Task CreateIndexAsync(string indexName, Type indexEntityType, int shard = 1, int
Task CreateIndexTemplateAsync(string indexTemplateName, string indexName, Type indexEntityType, int numberOfShards,
int numberOfReplicas);

Task CreateCollectionRouteKeyIndexAsync(Type indexEntityType, int numberOfShards,
int numberOfReplicas);
Task DeleteIndexAsync(string collectionName = null, CancellationToken cancellationToken = default);
}
Loading

0 comments on commit a620ce3

Please sign in to comment.