File tree Expand file tree Collapse file tree 4 files changed +35
-10
lines changed
lib/error_tracker/web/live Expand file tree Collapse file tree 4 files changed +35
-10
lines changed Original file line number Diff line number Diff line change @@ -64,14 +64,27 @@ defmodule ErrorTracker.Web.Live.Dashboard do
6464
6565 total_errors = Repo . aggregate ( query , :count )
6666
67- errors_query =
68- query
69- |> order_by ( desc: :last_occurrence_at )
70- |> offset ( ( ^ page - 1 ) * @ per_page )
71- |> limit ( @ per_page )
67+ errors =
68+ Repo . all (
69+ from query ,
70+ order_by: [ desc: :last_occurrence_at ] ,
71+ offset: ( ^ page - 1 ) * @ per_page ,
72+ limit: @ per_page
73+ )
74+
75+ error_ids = Enum . map ( errors , & & 1 . id )
76+
77+ occurrences =
78+ errors
79+ |> Ecto . assoc ( :occurrences )
80+ |> where ( [ o ] , o . error_id in ^ error_ids )
81+ |> group_by ( [ o ] , o . error_id )
82+ |> select ( [ o ] , { o . error_id , count ( o . id ) } )
83+ |> Repo . all ( )
7284
7385 assign ( socket ,
74- errors: Repo . all ( errors_query ) ,
86+ errors: errors ,
87+ occurrences: Map . new ( occurrences ) ,
7588 total_pages: ( total_errors / @ per_page ) |> Float . ceil ( ) |> trunc
7689 )
7790 end
Original file line number Diff line number Diff line change 4141 < thead class = "text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-600 dark:text-gray-400 " >
4242 < tr >
4343 < th scope = "col " class = "px-4 pr-2 py-3 w-128 " > Error</ th >
44- < th scope = "col " class = "px-4 py-3 w-72 " > Last occurrence </ th >
44+ < th scope = "col " class = "px-4 py-3 w-72 " > Occurrences </ th >
4545 < th scope = "col " class = "px-4 py-3 w-28 " > Status</ th >
4646 < th scope = "col " class = "px-4 py-3 w-32 " > </ th >
4747 </ tr >
6262 </ p >
6363 </ th >
6464 < td class = "px-4 py-4 " >
65- <%= format_datetime ( error . last_occurrence_at ) %>
65+ < p > Last: <%= format_datetime ( error . last_occurrence_at ) %> </ p >
66+ < p > Total: <%= @ occurrences [ error . id ] %> </ p >
6667 </ td >
6768 < td class = "px-4 py-4 " >
6869 < . badge :if = { error . status == :resolved } color = { :green } > Resolved</ . badge >
Original file line number Diff line number Diff line change @@ -104,7 +104,14 @@ defmodule ErrorTracker.Web.Live.Show do
104104 |> List . flatten ( )
105105 |> Enum . reverse ( )
106106
107- assign ( socket , :occurrences , occurrences )
107+ total_occurrences =
108+ socket . assigns . error
109+ |> Ecto . assoc ( :occurrences )
110+ |> Repo . aggregate ( :count )
111+
112+ socket
113+ |> assign ( :occurrences , occurrences )
114+ |> assign ( :total_occurrences , total_occurrences )
108115 end
109116
110117 defp related_occurrences ( query , num_results ) do
Original file line number Diff line number Diff line change 6363 </ div >
6464
6565 < div class = "px-3 md:pl-0 space-y-8 " >
66- < . section title = "Occurrence " >
66+ < . section title = { "Occurrence ( #{ @ total_occurrences } total)" } >
6767 < form phx-change = "occurrence_navigation " >
6868 < select name = "occurrence_id " class = "text-black w-full " >
6969 < option
8585 < pre > <%= format_datetime ( @ error . last_occurrence_at ) %> </ pre >
8686 </ . section >
8787
88+ < . section title = "First seen " >
89+ < pre > <%= format_datetime ( @ error . inserted_at ) %> </ pre >
90+ </ . section >
91+
8892 < . section title = "Status " title_class = "mb-3 " >
8993 < . badge :if = { @ error . status == :resolved } color = { :green } > Resolved</ . badge >
9094 < . badge :if = { @ error . status == :unresolved } color = { :red } > Unresolved</ . badge >
You can’t perform that action at this time.
0 commit comments