Index all workflow files. Only reprocesses changed files unless force_reindex=True.
(self, force_reindex: bool = False)
| 453 | return desc + "." |
| 454 | |
| 455 | def index_all_workflows(self, force_reindex: bool = False) -> Dict[str, int]: |
| 456 | """Index all workflow files. Only reprocesses changed files unless force_reindex=True.""" |
| 457 | if not os.path.exists(self.workflows_dir): |
| 458 | print(f"Warning: Workflows directory '{self.workflows_dir}' not found.") |
| 459 | return {"processed": 0, "skipped": 0, "errors": 0} |
| 460 | |
| 461 | workflows_path = Path(self.workflows_dir) |
| 462 | json_files = [str(p) for p in workflows_path.rglob("*.json")] |
| 463 | |
| 464 | if not json_files: |
| 465 | print(f"Warning: No JSON files found in '{self.workflows_dir}' directory.") |
| 466 | return {"processed": 0, "skipped": 0, "errors": 0} |
| 467 | |
| 468 | print(f"Indexing {len(json_files)} workflow files...") |
| 469 | |
| 470 | conn = sqlite3.connect(self.db_path) |
| 471 | conn.row_factory = sqlite3.Row |
| 472 | |
| 473 | stats = {"processed": 0, "skipped": 0, "errors": 0} |
| 474 | |
| 475 | for file_path in json_files: |
| 476 | filename = os.path.basename(file_path) |
| 477 | |
| 478 | try: |
| 479 | # Check if file needs to be reprocessed |
| 480 | if not force_reindex: |
| 481 | current_hash = self.get_file_hash(file_path) |
| 482 | cursor = conn.execute( |
| 483 | "SELECT file_hash FROM workflows WHERE filename = ?", |
| 484 | (filename,), |
| 485 | ) |
| 486 | row = cursor.fetchone() |
| 487 | if row and row["file_hash"] == current_hash: |
| 488 | stats["skipped"] += 1 |
| 489 | continue |
| 490 | |
| 491 | # Analyze workflow |
| 492 | workflow_data = self.analyze_workflow_file(file_path) |
| 493 | if not workflow_data: |
| 494 | stats["errors"] += 1 |
| 495 | continue |
| 496 | |
| 497 | # Insert or update in database |
| 498 | conn.execute( |
| 499 | """ |
| 500 | INSERT OR REPLACE INTO workflows ( |
| 501 | filename, name, workflow_id, active, description, trigger_type, |
| 502 | complexity, node_count, integrations, tags, created_at, updated_at, |
| 503 | file_hash, file_size, analyzed_at |
| 504 | ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) |
| 505 | """, |
| 506 | ( |
| 507 | workflow_data["filename"], |
| 508 | workflow_data["name"], |
| 509 | workflow_data["workflow_id"], |
| 510 | workflow_data["active"], |
| 511 | workflow_data["description"], |
| 512 | workflow_data["trigger_type"], |
no test coverage detected