合并云商品分支到 master 并适配插件结构
This commit is contained in:
commit
1fa91a9cfb
15 files changed
+968
-48
No files matched your search
@@ -25,9 +25,11 @@ namespace Store.Modules.CloudProduct.Services
|
||||
private readonly IOpenSearchService _searchService;
|
||||
private readonly IRawDataStorage _rawDataStorage;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly GoodsViolationService _violations;
|
||||
|
||||
public GoodsService(GoodsRepository repository, IOpenSearchService searchService, IRawDataStorage rawDataStorage, [FromKeyedServices("CloudProduct")] PluginContext context)
|
||||
public GoodsService(GoodsRepository repository, IOpenSearchService searchService, IRawDataStorage rawDataStorage, [FromKeyedServices("CloudProduct")] PluginContext context, GoodsViolationService violations)
|
||||
{
|
||||
_violations = violations;
|
||||
_repository = repository;
|
||||
_searchService = searchService;
|
||||
_rawDataStorage = rawDataStorage;
|
||||
@@ -148,7 +150,6 @@ namespace Store.Modules.CloudProduct.Services
|
||||
|
||||
var indexImmediately = IsImmediateIndexing();
|
||||
var documents = new List<GoodsSearchDocument>();
|
||||
var indexedIds = new List<long>();
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
@@ -196,7 +197,6 @@ namespace Store.Modules.CloudProduct.Services
|
||||
MinPrice = saved.MinPrice,
|
||||
SoldQuantity = saved.SoldQuantity,
|
||||
});
|
||||
indexedIds.Add(saved.GoodsId);
|
||||
}
|
||||
|
||||
result.SuccessCount++;
|
||||
@@ -212,7 +212,7 @@ namespace Store.Modules.CloudProduct.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
await _searchService.BulkIndexGoodsAsync(documents);
|
||||
var indexedIds = await _searchService.BulkIndexGoodsAsync(documents);
|
||||
await MarkIndexedAsync(indexedIds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -235,8 +235,9 @@ namespace Store.Modules.CloudProduct.Services
|
||||
if (batchSize <= 0)
|
||||
batchSize = 200;
|
||||
|
||||
var pending = await _repository.Select
|
||||
var pending = await _repository.Select.As("g")
|
||||
.Where(x => x.IsSegmented == 0 && x.Status == 0)
|
||||
.Where("NOT EXISTS (SELECT 1 FROM goods_violation v WHERE v.goods_id = g.goods_id)")
|
||||
.OrderBy(x => x.GoodsId)
|
||||
.Limit(batchSize)
|
||||
.ToListAsync();
|
||||
@@ -260,10 +261,9 @@ namespace Store.Modules.CloudProduct.Services
|
||||
})
|
||||
.ToList();
|
||||
|
||||
await _searchService.BulkIndexGoodsAsync(documents);
|
||||
|
||||
await MarkIndexedAsync(pending.Select(x => x.GoodsId));
|
||||
return pending.Count;
|
||||
var indexedIds = await _searchService.BulkIndexGoodsAsync(documents);
|
||||
await MarkIndexedAsync(indexedIds);
|
||||
return indexedIds.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -310,22 +310,22 @@ namespace Store.Modules.CloudProduct.Services
|
||||
/// </summary>
|
||||
public async Task<long> RebuildSearchIndexAsync(IEnumerable<long>? ids = null)
|
||||
{
|
||||
List<GoodsEntity> goodsList;
|
||||
|
||||
var idList = ids?.ToList();
|
||||
if (idList == null || idList.Count == 0)
|
||||
await _violations.DeleteViolationIndexesAsync(pendingOnly: false);
|
||||
var idList = ids?.Distinct().ToArray() ?? [];
|
||||
long lastId = 0, count = 0;
|
||||
while (true)
|
||||
{
|
||||
goodsList = await _repository.Select.ToListAsync();
|
||||
var goodsList = await _repository.Select.As("g")
|
||||
.Where(x => x.Status == 0 && x.GoodsId > 0 && x.Id > lastId)
|
||||
.WhereIf(idList.Length > 0, x => idList.Contains(x.GoodsId))
|
||||
.Where("NOT EXISTS (SELECT 1 FROM goods_violation v WHERE v.goods_id = g.goods_id)")
|
||||
.OrderBy(x => x.Id).Limit(1000).ToListAsync();
|
||||
if (goodsList.Count == 0) break;
|
||||
var indexedIds = await _searchService.RebuildIndexAsync(goodsList);
|
||||
await MarkIndexedAsync(indexedIds);
|
||||
count += indexedIds.Length;
|
||||
lastId = goodsList[^1].Id;
|
||||
}
|
||||
else
|
||||
{
|
||||
goodsList = await _repository.Select
|
||||
.Where(x => idList.Contains(x.GoodsId))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
var count = await _searchService.RebuildIndexAsync(goodsList);
|
||||
await MarkIndexedAsync(goodsList.Where(x => x.GoodsId > 0).Select(x => x.GoodsId));
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user