From adbcf2ae47d7ee5f1fb5703b8d4672ec2f356461 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sat, 22 Feb 2025 17:27:46 -0500 Subject: [PATCH] Unknown TG --- pkg/calls/callstore/store.go | 3 +++ pkg/database/calls.sql.go | 18 ++++++++++++++---- pkg/stats/stats.go | 1 - sql/postgres/queries/calls.sql | 6 ++++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/calls/callstore/store.go b/pkg/calls/callstore/store.go index 14e9716..e405ec2 100644 --- a/pkg/calls/callstore/store.go +++ b/pkg/calls/callstore/store.go @@ -204,6 +204,7 @@ type CallsParams struct { TagsNot []string `json:"tagsNot"` TGFilter *string `json:"tgFilter"` AtLeastSeconds *float32 `json:"atLeastSeconds"` + UnknownTG bool `json:"unknownTG"` } func (s *postgresStore) Calls(ctx context.Context, p CallsParams) (rows []database.ListCallsPRow, totalCount int, err error) { @@ -224,6 +225,7 @@ func (s *postgresStore) Calls(ctx context.Context, p CallsParams) (rows []databa PerPage: perPage, Direction: p.Direction.DirString(common.DirAsc), TGFilter: p.TGFilter, + UnknownTG: p.UnknownTG, } if p.AtLeastSeconds != nil { @@ -245,6 +247,7 @@ func (s *postgresStore) Calls(ctx context.Context, p CallsParams) (rows []databa TagsNot: par.TagsNot, TGFilter: par.TGFilter, LongerThan: par.LongerThan, + UnknownTG: par.UnknownTG, }) if err != nil { return err diff --git a/pkg/database/calls.sql.go b/pkg/database/calls.sql.go index 45d1702..120110f 100644 --- a/pkg/database/calls.sql.go +++ b/pkg/database/calls.sql.go @@ -319,6 +319,9 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN ) ELSE TRUE END) AND (CASE WHEN $6::NUMERIC IS NOT NULL THEN ( c.duration > $6 + ) ELSE TRUE END) AND +(CASE WHEN $7::BOOLEAN = TRUE THEN ( + tgs.tgid IS NULL ) ELSE TRUE END) ` @@ -329,6 +332,7 @@ type ListCallsCountParams struct { TagsNot []string `json:"tagsNot"` TGFilter *string `json:"tgFilter"` LongerThan pgtype.Numeric `json:"longerThan"` + UnknownTG bool `json:"unknownTg"` } func (q *Queries) ListCallsCount(ctx context.Context, arg ListCallsCountParams) (int64, error) { @@ -339,6 +343,7 @@ func (q *Queries) ListCallsCount(ctx context.Context, arg ListCallsCountParams) arg.TagsNot, arg.TGFilter, arg.LongerThan, + arg.UnknownTG, ) var count int64 err := row.Scan(&count) @@ -374,13 +379,16 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN ) ELSE TRUE END) AND (CASE WHEN $6::NUMERIC IS NOT NULL THEN ( c.duration > $6 + ) ELSE TRUE END) AND +(CASE WHEN $7::BOOLEAN = TRUE THEN ( + tgs.tgid IS NULL ) ELSE TRUE END) GROUP BY c.id, c.call_date ORDER BY -CASE WHEN $7::TEXT = 'asc' THEN c.call_date END ASC, -CASE WHEN $7 = 'desc' THEN c.call_date END DESC -OFFSET $8 ROWS -FETCH NEXT $9 ROWS ONLY +CASE WHEN $8::TEXT = 'asc' THEN c.call_date END ASC, +CASE WHEN $8 = 'desc' THEN c.call_date END DESC +OFFSET $9 ROWS +FETCH NEXT $10 ROWS ONLY ` type ListCallsPParams struct { @@ -390,6 +398,7 @@ type ListCallsPParams struct { TagsNot []string `json:"tagsNot"` TGFilter *string `json:"tgFilter"` LongerThan pgtype.Numeric `json:"longerThan"` + UnknownTG bool `json:"unknownTg"` Direction string `json:"direction"` Offset int32 `json:"offset"` PerPage int32 `json:"perPage"` @@ -413,6 +422,7 @@ func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListC arg.TagsNot, arg.TGFilter, arg.LongerThan, + arg.UnknownTG, arg.Direction, arg.Offset, arg.PerPage, diff --git a/pkg/stats/stats.go b/pkg/stats/stats.go index 5504935..a82991c 100644 --- a/pkg/stats/stats.go +++ b/pkg/stats/stats.go @@ -10,7 +10,6 @@ import ( "dynatron.me/x/stillbox/pkg/calls" "dynatron.me/x/stillbox/pkg/calls/callstore" "dynatron.me/x/stillbox/pkg/services" - "github.com/rs/zerolog/log" ) const DefaultExpiration = 5 * time.Minute diff --git a/sql/postgres/queries/calls.sql b/sql/postgres/queries/calls.sql index 0898863..13798c4 100644 --- a/sql/postgres/queries/calls.sql +++ b/sql/postgres/queries/calls.sql @@ -127,6 +127,9 @@ CASE WHEN sqlc.narg('tags_not')::TEXT[] IS NOT NULL THEN ) ELSE TRUE END) AND (CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN ( c.duration > @longer_than + ) ELSE TRUE END) AND +(CASE WHEN @unknown_tg::BOOLEAN = TRUE THEN ( + tgs.tgid IS NULL ) ELSE TRUE END) GROUP BY c.id, c.call_date ORDER BY @@ -157,6 +160,9 @@ CASE WHEN sqlc.narg('tags_not')::TEXT[] IS NOT NULL THEN ) ELSE TRUE END) AND (CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN ( c.duration > @longer_than + ) ELSE TRUE END) AND +(CASE WHEN @unknown_tg::BOOLEAN = TRUE THEN ( + tgs.tgid IS NULL ) ELSE TRUE END) ;