@@ -4,6 +4,7 @@ import { db, notes } from "../../db";
44import { eq , and } from "drizzle-orm" ;
55import { noteSchema , noteIdParamSchema } from "../../lib/openapi-schemas" ;
66import { invalidateNoteCounts } from "../../lib/cache" ;
7+ import { logger } from "../../lib/logger" ;
78
89const actionsRouter = new OpenAPIHono ( ) ;
910
@@ -40,14 +41,17 @@ actionsRouter.openapi(starNoteRoute, async (c) => {
4041 const userId = c . get ( "userId" ) ;
4142 const { id : noteId } = c . req . valid ( "param" ) ;
4243
44+ const selectStart = Date . now ( ) ;
4345 const existingNote = await db . query . notes . findFirst ( {
4446 where : and ( eq ( notes . id , noteId ) , eq ( notes . userId , userId ) ) ,
4547 } ) ;
48+ logger . databaseQuery ( "select" , "notes" , Date . now ( ) - selectStart , userId ) ;
4649
4750 if ( ! existingNote ) {
4851 throw new HTTPException ( 404 , { message : "Note not found" } ) ;
4952 }
5053
54+ const updateStart = Date . now ( ) ;
5155 const [ updatedNote ] = await db
5256 . update ( notes )
5357 . set ( {
@@ -56,6 +60,7 @@ actionsRouter.openapi(starNoteRoute, async (c) => {
5660 } )
5761 . where ( eq ( notes . id , noteId ) )
5862 . returning ( ) ;
63+ logger . databaseQuery ( "update" , "notes" , Date . now ( ) - updateStart , userId ) ;
5964
6065 // Invalidate counts cache for the note's folder hierarchy
6166 await invalidateNoteCounts ( userId , existingNote . folderId ) ;
@@ -96,14 +101,17 @@ actionsRouter.openapi(restoreNoteRoute, async (c) => {
96101 const userId = c . get ( "userId" ) ;
97102 const { id : noteId } = c . req . valid ( "param" ) ;
98103
104+ const selectStart = Date . now ( ) ;
99105 const existingNote = await db . query . notes . findFirst ( {
100106 where : and ( eq ( notes . id , noteId ) , eq ( notes . userId , userId ) ) ,
101107 } ) ;
108+ logger . databaseQuery ( "select" , "notes" , Date . now ( ) - selectStart , userId ) ;
102109
103110 if ( ! existingNote ) {
104111 throw new HTTPException ( 404 , { message : "Note not found" } ) ;
105112 }
106113
114+ const updateStart = Date . now ( ) ;
107115 const [ restoredNote ] = await db
108116 . update ( notes )
109117 . set ( {
@@ -113,6 +121,7 @@ actionsRouter.openapi(restoreNoteRoute, async (c) => {
113121 } )
114122 . where ( eq ( notes . id , noteId ) )
115123 . returning ( ) ;
124+ logger . databaseQuery ( "update" , "notes" , Date . now ( ) - updateStart , userId ) ;
116125
117126 // Invalidate counts cache for the note's folder hierarchy
118127 await invalidateNoteCounts ( userId , existingNote . folderId ) ;
@@ -156,9 +165,11 @@ actionsRouter.openapi(hideNoteRoute, async (c) => {
156165 const userId = c . get ( "userId" ) ;
157166 const { id : noteId } = c . req . valid ( "param" ) ;
158167
168+ const selectStart = Date . now ( ) ;
159169 const existingNote = await db . query . notes . findFirst ( {
160170 where : and ( eq ( notes . id , noteId ) , eq ( notes . userId , userId ) ) ,
161171 } ) ;
172+ logger . databaseQuery ( "select" , "notes" , Date . now ( ) - selectStart , userId ) ;
162173
163174 if ( ! existingNote ) {
164175 throw new HTTPException ( 404 , { message : "Note not found" } ) ;
@@ -168,6 +179,7 @@ actionsRouter.openapi(hideNoteRoute, async (c) => {
168179 throw new HTTPException ( 400 , { message : "Note is already hidden" } ) ;
169180 }
170181
182+ const updateStart = Date . now ( ) ;
171183 const [ hiddenNote ] = await db
172184 . update ( notes )
173185 . set ( {
@@ -177,6 +189,7 @@ actionsRouter.openapi(hideNoteRoute, async (c) => {
177189 } )
178190 . where ( eq ( notes . id , noteId ) )
179191 . returning ( ) ;
192+ logger . databaseQuery ( "update" , "notes" , Date . now ( ) - updateStart , userId ) ;
180193
181194 // Invalidate counts cache for the note's folder hierarchy
182195 await invalidateNoteCounts ( userId , existingNote . folderId ) ;
@@ -220,9 +233,11 @@ actionsRouter.openapi(unhideNoteRoute, async (c) => {
220233 const userId = c . get ( "userId" ) ;
221234 const { id : noteId } = c . req . valid ( "param" ) ;
222235
236+ const selectStart = Date . now ( ) ;
223237 const existingNote = await db . query . notes . findFirst ( {
224238 where : and ( eq ( notes . id , noteId ) , eq ( notes . userId , userId ) ) ,
225239 } ) ;
240+ logger . databaseQuery ( "select" , "notes" , Date . now ( ) - selectStart , userId ) ;
226241
227242 if ( ! existingNote ) {
228243 throw new HTTPException ( 404 , { message : "Note not found" } ) ;
@@ -232,6 +247,7 @@ actionsRouter.openapi(unhideNoteRoute, async (c) => {
232247 throw new HTTPException ( 400 , { message : "Note is not hidden" } ) ;
233248 }
234249
250+ const updateStart = Date . now ( ) ;
235251 const [ unhiddenNote ] = await db
236252 . update ( notes )
237253 . set ( {
@@ -241,6 +257,7 @@ actionsRouter.openapi(unhideNoteRoute, async (c) => {
241257 } )
242258 . where ( eq ( notes . id , noteId ) )
243259 . returning ( ) ;
260+ logger . databaseQuery ( "update" , "notes" , Date . now ( ) - updateStart , userId ) ;
244261
245262 // Invalidate counts cache for the note's folder hierarchy
246263 await invalidateNoteCounts ( userId , existingNote . folderId ) ;
0 commit comments