Skip to content

Commit

Permalink
feat: improve tx report
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Nov 27, 2024
1 parent a7b187a commit 1bb12a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 4 additions & 1 deletion go/summarize/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,16 @@ func renderTransactions(md *markdown.MarkDown, transactions []TransactionSummary
}
tables = uniquefy(tables)
md.NewLine()
md.Printf("Pattern %d (Observed %d times)\n\n", i+1, tx.Count)
md.PrintHeader(fmt.Sprintf("Pattern %d (Observed %d times)\n\n", i+1, tx.Count), 3)
md.Printf("Tables Involved: %s\n", strings.Join(tables, ", "))
md.PrintHeader("Query Patterns", 3)
for i, query := range tx.Queries {
md.Printf("%d. **%s** on `%s` \n", i+1, strings.ToTitle(query.Type), query.Table)
md.Printf(" Predicates: %s\n\n", strings.Join(query.Predicates, " AND "))
}
if i != len(transactions)-1 {
md.Printf("---\n")
}
}
}

Expand Down
16 changes: 14 additions & 2 deletions go/summarize/summarize-transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ import (

func summarizeTransactions(s *Summary, txs []transactions.Signature) error {
for _, tx := range txs {
patterns, interesting := summarizeQueries(tx.Queries)
if !interesting {
continue
}
s.transactions = append(s.transactions, TransactionSummary{
Count: tx.Count,
Queries: summarizeQueries(tx.Queries),
Queries: patterns,
})
}
return nil
}

func summarizeQueries(queries []transactions.Query) (patterns []QueryPattern) {
func summarizeQueries(queries []transactions.Query) (patterns []QueryPattern, interesting bool) {
for _, q := range queries {
if !interesting {
// Check if any of the predicates are interesting
for _, predicate := range q.Predicates {
if predicate.Val >= 0 {
interesting = true
}
}
}
patterns = append(patterns, QueryPattern{
Type: q.Op,
Table: q.AffectedTable,
Expand Down

0 comments on commit 1bb12a1

Please sign in to comment.