From b44a2f8809c5fb46d923bc381f70085f7ca9f5a3 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Fri, 25 May 2018 20:47:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Improve=20performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- build.gradle | 6 +++--- .../main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt | 2 +- .../dissem/bitmessage/ports/AbstractMessageRepository.kt | 4 ++-- .../ch/dissem/bitmessage/ports/MessageRepository.kt | 2 +- .../ch/dissem/bitmessage/utils/ConversationService.kt | 9 +++++---- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 98d31cd..91415dd 100644 --- a/.gitignore +++ b/.gitignore @@ -49,7 +49,7 @@ gradle-app.setting ## Plugin-specific files: # IntelliJ -/out/ +out/ # mpeltonen/sbt-idea plugin .idea_modules/ diff --git a/build.gradle b/build.gradle index 4e5bc5e..e716013 100644 --- a/build.gradle +++ b/build.gradle @@ -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') { diff --git a/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt b/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt index d341b66..607e060 100644 --- a/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt +++ b/core/src/main/kotlin/ch/dissem/bitmessage/entity/Plaintext.kt @@ -65,7 +65,7 @@ class Plaintext private constructor( val message: ByteArray, val ackData: ByteArray?, ackMessage: Lazy = 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, diff --git a/core/src/main/kotlin/ch/dissem/bitmessage/ports/AbstractMessageRepository.kt b/core/src/main/kotlin/ch/dissem/bitmessage/ports/AbstractMessageRepository.kt index 9df98a9..650a20d 100644 --- a/core/src/main/kotlin/ch/dissem/bitmessage/ports/AbstractMessageRepository.kt +++ b/core/src/main/kotlin/ch/dissem/bitmessage/ports/AbstractMessageRepository.kt @@ -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 { - 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) } /** diff --git a/core/src/main/kotlin/ch/dissem/bitmessage/ports/MessageRepository.kt b/core/src/main/kotlin/ch/dissem/bitmessage/ports/MessageRepository.kt index 95cd77e..720b98a 100644 --- a/core/src/main/kotlin/ch/dissem/bitmessage/ports/MessageRepository.kt +++ b/core/src/main/kotlin/ch/dissem/bitmessage/ports/MessageRepository.kt @@ -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> } diff --git a/core/src/main/kotlin/ch/dissem/bitmessage/utils/ConversationService.kt b/core/src/main/kotlin/ch/dissem/bitmessage/utils/ConversationService.kt index 5939c96..5585a1b 100644 --- a/core/src/main/kotlin/ch/dissem/bitmessage/utils/ConversationService.kt +++ b/core/src/main/kotlin/ch/dissem/bitmessage/utils/ConversationService.kt @@ -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 {