Index all notes at start
This commit is contained in:
@@ -26,7 +26,7 @@ val domainModule = module {
|
||||
single<PasswordHash> { BcryptPasswordHash() }
|
||||
single { SimpleJwt(get()) }
|
||||
single { JwtPayloadExtractor(get()) }
|
||||
single { NoteService(get(), get(), get()) }
|
||||
single { NoteService(get(), get(), get(), get()) }
|
||||
single<MarkdownConverter> { MarkdownConverterImpl() }
|
||||
single<ExportUseCase> { ExportUseCaseImpl(get()) }
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ import be.simplenotes.domain.security.HtmlSanitizer
|
||||
import be.simplenotes.domain.usecases.markdown.MarkdownConverter
|
||||
import be.simplenotes.domain.usecases.markdown.MarkdownParsingError
|
||||
import be.simplenotes.domain.usecases.repositories.NoteRepository
|
||||
import be.simplenotes.domain.usecases.repositories.UserRepository
|
||||
import be.simplenotes.search.NoteSearcher
|
||||
import java.util.*
|
||||
|
||||
class NoteService(
|
||||
private val markdownConverter: MarkdownConverter,
|
||||
private val noteRepository: NoteRepository,
|
||||
private val userRepository: UserRepository,
|
||||
private val searcher: NoteSearcher,
|
||||
) {
|
||||
|
||||
@@ -74,6 +76,13 @@ class NoteService(
|
||||
|
||||
fun countDeleted(userId: Int) = noteRepository.count(userId, deleted = true)
|
||||
|
||||
fun indexAll() {
|
||||
val userIds = userRepository.findAll()
|
||||
userIds.forEach { id ->
|
||||
val notes = noteRepository.findAllDetails(id)
|
||||
searcher.indexNotes(id, notes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class PaginatedNotes(val pages: Int, val notes: List<PersistedNoteMetadata>)
|
||||
|
||||
@@ -27,4 +27,5 @@ interface NoteRepository {
|
||||
fun find(userId: Int, uuid: UUID): PersistedNote?
|
||||
fun update(userId: Int, uuid: UUID, note: Note): PersistedNote?
|
||||
fun export(userId: Int): List<ExportedNote>
|
||||
fun findAllDetails(userId: Int): List<PersistedNote>
|
||||
}
|
||||
|
||||
@@ -10,4 +10,5 @@ interface UserRepository {
|
||||
fun exists(username: String): Boolean
|
||||
fun exists(id: Int): Boolean
|
||||
fun delete(id: Int): Boolean
|
||||
fun findAll(): List<Int>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user