Limit object creation in getNotes

This commit is contained in:
Hubert Van De Walle 2020-04-24 00:20:28 +02:00
parent feeee20bfe
commit 6e4fa89e85

View File

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