-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstats_pipeline_items.go
More file actions
109 lines (95 loc) · 3.3 KB
/
Copy pathstats_pipeline_items.go
File metadata and controls
109 lines (95 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package store
import (
"context"
"github.com/darron/dbrain/internal/model"
)
func (s *Store) pipelineAppleNoteExtractionRow(ctx context.Context) (PipelineStageRow, bool, error) {
candidateWhere := `source_type = 'apple_note'`
total, err := s.countWhere(ctx, "items", candidateWhere)
if err != nil {
return PipelineStageRow{}, false, err
}
if total == 0 {
return PipelineStageRow{}, false, nil
}
current, err := s.countWhere(ctx, "items", candidateWhere+` AND (text != '' OR article_text != '')`)
if err != nil {
return PipelineStageRow{}, false, err
}
blocked, err := s.countWhere(ctx, "items", candidateWhere+` AND text = '' AND article_text = ''`)
if err != nil {
return PipelineStageRow{}, false, err
}
row := PipelineStageRow{
Kind: pipelineKindAppleNote,
Total: total,
Current: current,
Blocked: blocked,
}
finalizePipelineStageRow(&row)
return row, true, nil
}
func (s *Store) pipelineSafariTabExtractionRow(ctx context.Context) (PipelineStageRow, bool, error) {
candidateWhere := `source_type = 'safari_tab'`
total, err := s.countWhere(ctx, "items", candidateWhere)
if err != nil {
return PipelineStageRow{}, false, err
}
if total == 0 {
return PipelineStageRow{}, false, nil
}
current, err := s.countWhere(ctx, "items", candidateWhere+` AND text != '' AND canonical_url != ''`)
if err != nil {
return PipelineStageRow{}, false, err
}
blocked, err := s.countWhere(ctx, "items", candidateWhere+` AND (text = '' OR canonical_url = '')`)
if err != nil {
return PipelineStageRow{}, false, err
}
row := PipelineStageRow{
Kind: pipelineKindSafariTab,
Total: total,
Current: current,
Blocked: blocked,
}
finalizePipelineStageRow(&row)
return row, true, nil
}
func (s *Store) pipelineAppleNoteSummaryRow(ctx context.Context) (PipelineStageRow, bool, error) {
candidateWhere := `source_type = 'apple_note' AND (text != '' OR article_text != '')`
summaryStatus := itemSummaryStatusExpr()
summaryText := itemSummaryTextExpr()
total, err := s.countWhere(ctx, "items", candidateWhere)
if err != nil {
return PipelineStageRow{}, false, err
}
if total == 0 {
return PipelineStageRow{}, false, nil
}
current, err := s.countWhere(ctx, "items", candidateWhere+` AND `+summaryStatus+` = '`+model.ItemSummaryStatusOK+`' AND `+summaryText+` != ''`)
if err != nil {
return PipelineStageRow{}, false, err
}
pending, err := s.countWhere(ctx, "items", candidateWhere+` AND (`+summaryStatus+` = '' OR `+summaryStatus+` = '`+model.ItemSummaryStatusError+`')`)
if err != nil {
return PipelineStageRow{}, false, err
}
blocked, err := s.countWhere(ctx, "items", candidateWhere+` AND `+summaryStatus+` IN ('`+model.ItemSummaryStatusBlocked+`', '`+model.ItemSummaryStatusSkipped+`')`)
if err != nil {
return PipelineStageRow{}, false, err
}
failed, err := s.countWhere(ctx, "items", candidateWhere+` AND `+summaryStatus+` != '' AND `+summaryStatus+` NOT IN ('`+model.ItemSummaryStatusOK+`', '`+model.ItemSummaryStatusError+`', '`+model.ItemSummaryStatusBlocked+`', '`+model.ItemSummaryStatusSkipped+`')`)
if err != nil {
return PipelineStageRow{}, false, err
}
row := PipelineStageRow{
Kind: pipelineKindAppleNote,
Total: total,
Current: current,
Pending: pending,
Blocked: blocked,
Failed: failed,
}
finalizePipelineStageRow(&row)
return row, true, nil
}