slow version
This commit is contained in:
parent
108c6ec62f
commit
91e9b2ed8e
2 changed files with 19 additions and 19 deletions
|
@ -255,13 +255,13 @@ SELECT
|
||||||
c.id,
|
c.id,
|
||||||
c.call_date,
|
c.call_date,
|
||||||
c.duration,
|
c.duration,
|
||||||
tgs.system_id,
|
c.system,
|
||||||
tgs.tgid,
|
c.talkgroup,
|
||||||
sys.name system_name,
|
COUNT(ic.incident_id) incidents
|
||||||
tgs.name tg_name
|
|
||||||
FROM calls c
|
FROM calls c
|
||||||
JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id
|
JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id
|
||||||
JOIN systems sys ON sys.id = tgs.system_id
|
JOIN systems sys ON sys.id = tgs.system_id
|
||||||
|
LEFT JOIN incidents_calls ic ON c.id = ic.calls_tbl_id AND c.call_date = ic.call_date
|
||||||
WHERE
|
WHERE
|
||||||
CASE WHEN $1::TIMESTAMPTZ IS NOT NULL THEN
|
CASE WHEN $1::TIMESTAMPTZ IS NOT NULL THEN
|
||||||
c.call_date >= $1 ELSE TRUE END AND
|
c.call_date >= $1 ELSE TRUE END AND
|
||||||
|
@ -279,6 +279,7 @@ CASE WHEN $4::TEXT[] IS NOT NULL THEN
|
||||||
(CASE WHEN $6::NUMERIC IS NOT NULL THEN (
|
(CASE WHEN $6::NUMERIC IS NOT NULL THEN (
|
||||||
c.duration > $6
|
c.duration > $6
|
||||||
) ELSE TRUE END)
|
) ELSE TRUE END)
|
||||||
|
GROUP BY c.id, c.call_date
|
||||||
ORDER BY
|
ORDER BY
|
||||||
CASE WHEN $7::TEXT = 'asc' THEN c.call_date END ASC,
|
CASE WHEN $7::TEXT = 'asc' THEN c.call_date END ASC,
|
||||||
CASE WHEN $7 = 'desc' THEN c.call_date END DESC
|
CASE WHEN $7 = 'desc' THEN c.call_date END DESC
|
||||||
|
@ -299,13 +300,12 @@ type ListCallsPParams struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCallsPRow struct {
|
type ListCallsPRow struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
CallDate pgtype.Timestamptz `json:"call_date"`
|
CallDate pgtype.Timestamptz `json:"call_date"`
|
||||||
Duration *int32 `json:"duration"`
|
Duration *int32 `json:"duration"`
|
||||||
SystemID int32 `json:"system_id"`
|
System int `json:"system"`
|
||||||
TGID int32 `json:"tgid"`
|
Talkgroup int `json:"talkgroup"`
|
||||||
SystemName string `json:"system_name"`
|
Incidents int64 `json:"incidents"`
|
||||||
TGName *string `json:"tg_name"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListCallsPRow, error) {
|
func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListCallsPRow, error) {
|
||||||
|
@ -331,10 +331,9 @@ func (q *Queries) ListCallsP(ctx context.Context, arg ListCallsPParams) ([]ListC
|
||||||
&i.ID,
|
&i.ID,
|
||||||
&i.CallDate,
|
&i.CallDate,
|
||||||
&i.Duration,
|
&i.Duration,
|
||||||
&i.SystemID,
|
&i.System,
|
||||||
&i.TGID,
|
&i.Talkgroup,
|
||||||
&i.SystemName,
|
&i.Incidents,
|
||||||
&i.TGName,
|
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,13 +101,13 @@ SELECT
|
||||||
c.id,
|
c.id,
|
||||||
c.call_date,
|
c.call_date,
|
||||||
c.duration,
|
c.duration,
|
||||||
tgs.system_id,
|
c.system,
|
||||||
tgs.tgid,
|
c.talkgroup,
|
||||||
sys.name system_name,
|
COUNT(ic.incident_id) incidents
|
||||||
tgs.name tg_name
|
|
||||||
FROM calls c
|
FROM calls c
|
||||||
JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id
|
JOIN talkgroups tgs ON c.talkgroup = tgs.tgid AND c.system = tgs.system_id
|
||||||
JOIN systems sys ON sys.id = tgs.system_id
|
JOIN systems sys ON sys.id = tgs.system_id
|
||||||
|
LEFT JOIN incidents_calls ic ON c.id = ic.calls_tbl_id AND c.call_date = ic.call_date
|
||||||
WHERE
|
WHERE
|
||||||
CASE WHEN sqlc.narg('start')::TIMESTAMPTZ IS NOT NULL THEN
|
CASE WHEN sqlc.narg('start')::TIMESTAMPTZ IS NOT NULL THEN
|
||||||
c.call_date >= @start ELSE TRUE END AND
|
c.call_date >= @start ELSE TRUE END AND
|
||||||
|
@ -125,6 +125,7 @@ CASE WHEN sqlc.narg('tags_not')::TEXT[] IS NOT NULL THEN
|
||||||
(CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN (
|
(CASE WHEN sqlc.narg('longer_than')::NUMERIC IS NOT NULL THEN (
|
||||||
c.duration > @longer_than
|
c.duration > @longer_than
|
||||||
) ELSE TRUE END)
|
) ELSE TRUE END)
|
||||||
|
GROUP BY c.id, c.call_date
|
||||||
ORDER BY
|
ORDER BY
|
||||||
CASE WHEN @direction::TEXT = 'asc' THEN c.call_date END ASC,
|
CASE WHEN @direction::TEXT = 'asc' THEN c.call_date END ASC,
|
||||||
CASE WHEN @direction = 'desc' THEN c.call_date END DESC
|
CASE WHEN @direction = 'desc' THEN c.call_date END DESC
|
||||||
|
|
Loading…
Reference in a new issue