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:
@@ -47,7 +47,16 @@ func (c *Connector) Validate(ctx context.Context, config *types.DataSourceConfig
|
||||
// ListResources lists all accessible Notion pages and databases as selectable resources.
|
||||
// Returns all objects with parent-child relationships populated, allowing the frontend
|
||||
// to render a tree view. Root objects have empty ParentID.
|
||||
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) {
|
||||
// Notion returns the full hierarchy (with parent_id populated) in a single
|
||||
// call, so children are already delivered with the root listing. Lazy-load
|
||||
// requests for a specific parent therefore have nothing extra to return.
|
||||
if parentID != "" {
|
||||
return []types.Resource{}, nil
|
||||
}
|
||||
|
||||
notionCfg, err := parseNotionConfig(config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -903,7 +912,7 @@ func computeExcludedSet(visibleIDs []string, parentOf map[string]string, selecte
|
||||
// and computes the deselected set. Used by FetchAll where no other code path
|
||||
// already has the page list in hand.
|
||||
func (c *Connector) excludedSetFromListResources(ctx context.Context, config *types.DataSourceConfig, selectedIDs []string) map[string]bool {
|
||||
visible, err := c.ListResources(ctx, config)
|
||||
visible, err := c.ListResources(ctx, config, "")
|
||||
if err != nil {
|
||||
logger.Warnf(ctx, "[Notion] failed to list visible resources for exclusion: %v", err)
|
||||
return map[string]bool{}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestConnectorListResources(t *testing.T) {
|
||||
defer ts.Close()
|
||||
|
||||
c := NewConnector()
|
||||
resources, err := c.ListResources(context.Background(), makeNotionConfig(cfg, ts.URL, nil))
|
||||
resources, err := c.ListResources(context.Background(), makeNotionConfig(cfg, ts.URL, nil), "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListResources() error: %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user