🚀 Improve performance
This commit is contained in:
		
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -49,7 +49,7 @@ gradle-app.setting | ||||
| ## Plugin-specific files: | ||||
|  | ||||
| # IntelliJ | ||||
| /out/ | ||||
| out/ | ||||
|  | ||||
| # mpeltonen/sbt-idea plugin | ||||
| .idea_modules/ | ||||
|   | ||||
| @@ -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') { | ||||
|   | ||||
| @@ -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, | ||||
|   | ||||
| @@ -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) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -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> | ||||
| } | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user