feat(plugin): list 方法集成 Generated Column 路由
- list 方法新增 cache 参数,使用 resolve_entity_info_cached 替代直接查库 - 查询改用 build_filtered_query_sql_ex,自动路由到 Generated Column - handler 传递 entity_cache 到 list 方法
This commit is contained in:
@@ -59,7 +59,7 @@ impl PluginDataService {
|
||||
})
|
||||
}
|
||||
|
||||
/// 列表查询(支持过滤/搜索/排序)
|
||||
/// 列表查询(支持过滤/搜索/排序/Generated Column 路由)
|
||||
pub async fn list(
|
||||
plugin_id: Uuid,
|
||||
entity_name: &str,
|
||||
@@ -71,8 +71,10 @@ impl PluginDataService {
|
||||
search: Option<String>,
|
||||
sort_by: Option<String>,
|
||||
sort_order: Option<String>,
|
||||
cache: &moka::sync::Cache<String, EntityInfo>,
|
||||
) -> AppResult<(Vec<PluginDataResp>, u64)> {
|
||||
let info = resolve_entity_info(plugin_id, entity_name, tenant_id, db).await?;
|
||||
let info =
|
||||
resolve_entity_info_cached(plugin_id, entity_name, tenant_id, db, cache).await?;
|
||||
|
||||
// 获取 searchable 字段列表
|
||||
let entity_fields = info.fields()?;
|
||||
@@ -105,9 +107,9 @@ impl PluginDataService {
|
||||
.map(|r| r.count as u64)
|
||||
.unwrap_or(0);
|
||||
|
||||
// Query
|
||||
// Query — 使用 Generated Column 路由
|
||||
let offset = page.saturating_sub(1) * page_size;
|
||||
let (sql, values) = DynamicTableManager::build_filtered_query_sql(
|
||||
let (sql, values) = DynamicTableManager::build_filtered_query_sql_ex(
|
||||
&info.table_name,
|
||||
tenant_id,
|
||||
page_size,
|
||||
@@ -116,6 +118,7 @@ impl PluginDataService {
|
||||
search_tuple,
|
||||
sort_by,
|
||||
sort_order,
|
||||
&info.generated_fields,
|
||||
)
|
||||
.map_err(|e| AppError::Validation(e))?;
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ where
|
||||
params.search,
|
||||
params.sort_by,
|
||||
params.sort_order,
|
||||
&state.entity_cache,
|
||||
)
|
||||
.await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user