()
| 537 | } |
| 538 | |
| 539 | async getStats() { |
| 540 | if (!this.initialized) { |
| 541 | await this.initialize(); |
| 542 | } |
| 543 | |
| 544 | return new Promise((resolve, reject) => { |
| 545 | const queries = [ |
| 546 | "SELECT COUNT(*) as total FROM workflows", |
| 547 | "SELECT COUNT(*) as active FROM workflows WHERE active = 1", |
| 548 | "SELECT COUNT(*) as inactive FROM workflows WHERE active = 0", |
| 549 | "SELECT trigger_type, COUNT(*) as count FROM workflows GROUP BY trigger_type", |
| 550 | "SELECT complexity, COUNT(*) as count FROM workflows GROUP BY complexity", |
| 551 | "SELECT SUM(node_count) as total_nodes FROM workflows", |
| 552 | "SELECT analyzed_at FROM workflows ORDER BY analyzed_at DESC LIMIT 1", |
| 553 | ]; |
| 554 | |
| 555 | Promise.all( |
| 556 | queries.map( |
| 557 | (sql) => |
| 558 | new Promise((resolve, reject) => { |
| 559 | this.db.all(sql, (err, rows) => { |
| 560 | if (err) reject(err); |
| 561 | else resolve(rows); |
| 562 | }); |
| 563 | }) |
| 564 | ) |
| 565 | ) |
| 566 | .then((results) => { |
| 567 | const [ |
| 568 | total, |
| 569 | active, |
| 570 | inactive, |
| 571 | triggers, |
| 572 | complexity, |
| 573 | nodes, |
| 574 | lastIndexed, |
| 575 | ] = results; |
| 576 | |
| 577 | const triggersMap = {}; |
| 578 | triggers.forEach((row) => { |
| 579 | triggersMap[row.trigger_type] = row.count; |
| 580 | }); |
| 581 | |
| 582 | const complexityMap = {}; |
| 583 | complexity.forEach((row) => { |
| 584 | complexityMap[row.complexity] = row.count; |
| 585 | }); |
| 586 | |
| 587 | // Count unique integrations |
| 588 | this.db.all("SELECT integrations FROM workflows", (err, rows) => { |
| 589 | if (err) { |
| 590 | reject(err); |
| 591 | return; |
| 592 | } |
| 593 | |
| 594 | const allIntegrations = new Set(); |
| 595 | rows.forEach((row) => { |
| 596 | try { |
no test coverage detected