Skip to content

Commit

Permalink
e2pg: perf. speed up main dashboard query
Browse files Browse the repository at this point in the history
  • Loading branch information
ryandotsmith committed Oct 16, 2023
1 parent de8ec1a commit 24cc79d
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions e2pg/e2pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,19 +479,23 @@ func TaskUpdate1(ctx context.Context, pg wpg.Conn, id string) (TaskUpdate, error

func TaskUpdates(ctx context.Context, pg wpg.Conn) ([]TaskUpdate, error) {
rows, _ := pg.Query(ctx, `
select distinct on (id)
id,
num,
hash,
coalesce(src_num, 0) src_num,
coalesce(src_hash, '\x00') src_hash,
coalesce(nblocks, 0) nblocks,
coalesce(nrows, 0) nrows,
coalesce(latency, '0')::interval latency,
coalesce(dstat, '{}') dstat
from e2pg.task
order by id, num desc;
`)
with f as (
select id, max(num) num
from e2pg.task group by 1
)
select
f.id,
f.num,
hash,
coalesce(src_num, 0) src_num,
coalesce(src_hash, '\x00') src_hash,
coalesce(nblocks, 0) nblocks,
coalesce(nrows, 0) nrows,
coalesce(latency, '0')::interval latency,
coalesce(dstat, '{}') dstat
from f
left join e2pg.task on e2pg.task.id = f.id and e2pg.task.num = f.num;
`)
return pgx.CollectRows(rows, pgx.RowToStructByName[TaskUpdate])
}

Expand Down

0 comments on commit 24cc79d

Please sign in to comment.