fix(datasource): lazy-load Feishu wiki resources to avoid listing timeout (#1672)
Listing resources for a Feishu data source eagerly walked the entire wiki tree (one API call per node across every space), which exceeded the request timeout for large knowledge bases. ListResources now takes a parentID and returns a single level at a time: empty lists the wiki spaces, a space/node ID lists only its direct children. The frontend fetches children on demand when a node is expanded. Notion (full tree in one call) and Yuque (flat) keep their existing behavior by ignoring non-empty parentID. Refs: https://github.com/Tencent/WeKnora/issues/1672
This commit is contained in:
@@ -42,7 +42,15 @@ func (c *Connector) Validate(ctx context.Context, config *types.DataSourceConfig
|
||||
|
||||
// ListResources returns all repos (personal + team) accessible to the token.
|
||||
// Serial fetch for v1 (user groups typically <10). TODO(perf): parallelize if slow.
|
||||
func (c *Connector) ListResources(ctx context.Context, config *types.DataSourceConfig) ([]types.Resource, error) {
|
||||
func (c *Connector) ListResources(
|
||||
ctx context.Context, config *types.DataSourceConfig, parentID string,
|
||||
) ([]types.Resource, error) {
|
||||
// Yuque resources are a flat list of repositories (no nesting), so a
|
||||
// lazy-load request for a specific parent has nothing extra to return.
|
||||
if parentID != "" {
|
||||
return []types.Resource{}, nil
|
||||
}
|
||||
|
||||
cfg, err := parseYuqueConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -69,7 +69,7 @@ func TestConnector_ListResources_Aggregates(t *testing.T) {
|
||||
{ID: 30, Slug: "bb", Name: "B Book", Type: "Book", Namespace: "team-b/bb"},
|
||||
}})
|
||||
|
||||
resources, err := NewConnector().ListResources(context.Background(), makeDSConfig(f, nil))
|
||||
resources, err := NewConnector().ListResources(context.Background(), makeDSConfig(f, nil), "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListResources: %v", err)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ func TestConnector_ListResources_DedupByID(t *testing.T) {
|
||||
{ID: 99, Slug: "shared", Type: "Book", Namespace: "alice/shared"},
|
||||
}})
|
||||
|
||||
resources, err := NewConnector().ListResources(context.Background(), makeDSConfig(f, nil))
|
||||
resources, err := NewConnector().ListResources(context.Background(), makeDSConfig(f, nil), "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListResources: %v", err)
|
||||
}
|
||||
@@ -457,7 +457,7 @@ func TestConnector_ListResources_ContinuesOnGroupFailure(t *testing.T) {
|
||||
_, _ = w.Write([]byte(`{"message":"forbidden"}`))
|
||||
})
|
||||
|
||||
resources, err := NewConnector().ListResources(context.Background(), makeDSConfig(f, nil))
|
||||
resources, err := NewConnector().ListResources(context.Background(), makeDSConfig(f, nil), "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListResources should not fail on per-group error, got %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user