@@ -42,8 +42,7 @@ export const load: PageServerLoad = async ({ url, setHeaders }) => {
4242 firstLikedTweet ,
4343 monthData ,
4444 hasNextMonth ,
45- heatLikes ,
46- heatRetweets ,
45+ heatTweets ,
4746 ] = await Promise . all ( [
4847 db . query . likedTweets . findMany ( {
4948 columns : {
@@ -116,22 +115,31 @@ export const load: PageServerLoad = async ({ url, setHeaders }) => {
116115 startingFrom . add ( 1 , "month" ) . startOf ( "month" ) . toDate ( ) ,
117116 ) ,
118117 } ) ,
119- db . query . likedTweets . findMany ( {
120- columns : { firstSeenAt : true } ,
118+ db . query . tweets . findMany ( {
119+ columns : { } ,
120+ extras : {
121+ timestamp :
122+ sql < number > `(${ schema . tweets . twitterScraperJson } ->>'timestamp')::numeric` . as (
123+ "timestamp" ,
124+ ) ,
125+ isRetweet :
126+ sql < boolean > `(${ schema . tweets . twitterScraperJson } ->>'isRetweet')::boolean` . as (
127+ "isRetweet" ,
128+ ) ,
129+ } ,
121130 where : and (
122- gte ( schema . likedTweets . firstSeenAt , heatmapStart . toDate ( ) ) ,
123- lte ( schema . likedTweets . firstSeenAt , heatmapEnd . toDate ( ) ) ,
124- likesCutoffSql ,
131+ gte (
132+ sql `(${ schema . tweets . twitterScraperJson } ->>'timestamp')::numeric` ,
133+ + heatmapStart / 1000 ,
134+ ) ,
135+ lte (
136+ sql `(${ schema . tweets . twitterScraperJson } ->>'timestamp')::numeric` ,
137+ + heatmapEnd / 1000 ,
138+ ) ,
125139 ) ,
126- orderBy : desc ( schema . likedTweets . firstSeenAt ) ,
127- } ) ,
128- db . query . retweets . findMany ( {
129- columns : { retweetAt : true } ,
130- where : and (
131- gte ( schema . retweets . retweetAt , heatmapStart . toDate ( ) ) ,
132- lte ( schema . retweets . retweetAt , heatmapEnd . toDate ( ) ) ,
140+ orderBy : desc (
141+ sql `(${ schema . tweets . twitterScraperJson } ->>'timestamp')::numeric` ,
133142 ) ,
134- orderBy : desc ( schema . retweets . retweetAt ) ,
135143 } ) ,
136144 ] ) ;
137145 const t1 = performance . now ( ) ;
@@ -155,8 +163,9 @@ export const load: PageServerLoad = async ({ url, setHeaders }) => {
155163 }
156164 hourHeatmap [ dow ] [ hour ] ++ ;
157165 } ;
158- heatLikes . forEach ( ( t : { firstSeenAt : Date } ) => addToHeat ( t . firstSeenAt ) ) ;
159- heatRetweets . forEach ( ( t : { retweetAt : Date } ) => addToHeat ( t . retweetAt ) ) ;
166+ heatTweets . forEach ( ( t : { timestamp : number } ) => {
167+ addToHeat ( new Date ( t . timestamp * 1000 ) ) ;
168+ } ) ;
160169 console . timeEnd ( "heatmap" ) ;
161170
162171 if (
0 commit comments