🚀 Improve performance

This commit is contained in:
Christian Basler 2018-05-25 20:47:40 +02:00
parent c7c285a2c1
commit b44a2f8809
6 changed files with 13 additions and 12 deletions

2
.gitignore vendored
View File

@ -49,7 +49,7 @@ gradle-app.setting
## Plugin-specific files:
# IntelliJ
/out/
out/
# mpeltonen/sbt-idea plugin
.idea_modules/

View File

@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.2.30'
ext.kotlin_version = '1.2.41'
repositories {
mavenCentral()
}
@ -31,7 +31,7 @@ subprojects {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7"
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
compile "org.jetbrains.kotlin:kotlin-reflect"
}
@ -130,7 +130,7 @@ subprojects {
dependencyManagement {
dependencies {
dependencySet(group: 'org.jetbrains.kotlin', version: "$kotlin_version") {
entry 'kotlin-stdlib-jre7'
entry 'kotlin-stdlib-jdk7'
entry 'kotlin-reflect'
}
dependencySet(group: 'org.slf4j', version: '1.7.25') {

View File

@ -65,7 +65,7 @@ class Plaintext private constructor(
val message: ByteArray,
val ackData: ByteArray?,
ackMessage: Lazy<ObjectMessage?> = lazy { Factory.createAck(from, ackData, ttl) },
val conversationId: UUID = UUID.randomUUID(),
var conversationId: UUID = UUID.randomUUID(),
var inventoryVector: InventoryVector? = null,
var signature: ByteArray? = null,
sent: Long? = null,

View File

@ -109,8 +109,8 @@ abstract class AbstractMessageRepository : MessageRepository, InternalContext.Co
return find("iv IN (SELECT child FROM Message_Parent WHERE parent=X'${Strings.hex(parent.inventoryVector!!.hash)}')")
}
override fun getConversation(conversationId: UUID): List<Plaintext> {
return find("conversation=X'${conversationId.toString().replace("-", "")}'")
override fun getConversation(conversationId: UUID, offset: Int, limit: Int): List<Plaintext> {
return find("conversation=X'${conversationId.toString().replace("-", "")}'", offset, limit)
}
/**

View File

@ -68,5 +68,5 @@ interface MessageRepository {
* *
* @return all messages with the given conversation ID
*/
fun getConversation(conversationId: UUID): Collection<Plaintext>
fun getConversation(conversationId: UUID, offset: Int = 0, limit: Int = 0): Collection<Plaintext>
}

View File

@ -33,8 +33,9 @@ class ConversationService(private val messageRepository: MessageRepository) {
private val SUBJECT_PREFIX = Pattern.compile("^(re|fwd?):\\s*", CASE_INSENSITIVE)
fun findConversations(label: Label?, offset: Int = 0, limit: Int = 0) = messageRepository.findConversations(label, offset, limit)
.map { getConversation(it) }
fun findConversations(label: Label?, offset: Int = 0, limit: Int = 0, conversationLimit: Int = 10) =
messageRepository.findConversations(label, offset, limit)
.map { getConversation(it, conversationLimit) }
/**
* Retrieve the whole conversation from one single message. If the message isn't part
@ -62,8 +63,8 @@ class ConversationService(private val messageRepository: MessageRepository) {
return result
}
fun getConversation(conversationId: UUID): Conversation {
val messages = sorted(messageRepository.getConversation(conversationId))
fun getConversation(conversationId: UUID, limit: Int = 0): Conversation {
val messages = sorted(messageRepository.getConversation(conversationId, 0, limit))
val map = HashMap<InventoryVector, Plaintext>(messages.size)
for (message in messages) {
message.inventoryVector?.let {