Merge branch 'optimizations/notes-endpoint-perf' into feature/notes-table

This commit is contained in:
Hubert Van De Walle 2020-04-24 11:31:24 +02:00
commit ebd647a1a9
2 changed files with 4 additions and 11 deletions

View File

@ -7,8 +7,6 @@ import io.ktor.jackson.*
fun Application.contentNegotiationFeature() {
install(ContentNegotiation) {
jackson {
enable(SerializationFeature.INDENT_OUTPUT)
}
jackson {}
}
}

View File

@ -25,19 +25,14 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
.where { Notes.userId eq userId }
.orderBy(Notes.updatedAt.desc())
.map { row ->
Notes.createEntity(row)
}
.toList()
.map { note ->
val tags = db.from(Tags)
.select(Tags.name)
.where { Tags.noteId eq note.id }
.where { Tags.noteId eq row[Notes.id]!! }
.map { it[Tags.name]!! }
.toList()
val updatedAt = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(note.updatedAt)
val updatedAt = DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(row[Notes.updatedAt]!!)
NotesDTO(note.title, tags, updatedAt)
NotesDTO(row[Notes.title]!!, tags, updatedAt)
}
fun getNoteIdFromUserIdAndTitle(userId: Int, noteTitle: String): Int? = db.from(Notes)