RED-3932 - performance update

This commit is contained in:
Timo Bejan 2022-04-26 17:51:41 +03:00
parent 1b488b1919
commit 16defeeb71
4 changed files with 58 additions and 10 deletions

View File

@ -1,15 +1,13 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence.repository;
import java.util.List;
import java.util.Set;
import javax.transaction.Transactional;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.DictionaryEntryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.DictionaryEntryEntity;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Set;
public interface EntryRepository extends JpaRepository<DictionaryEntryEntity, Long> {
@ -35,8 +33,8 @@ public interface EntryRepository extends JpaRepository<DictionaryEntryEntity, Lo
void deleteAllEntriesForTypeId(String typeId, long version);
@Modifying
@Modifying(flushAutomatically = true, clearAutomatically = true)
@Transactional
@Query(value = "update dictionary_entry set deleted = true, version = :version where type_id = :typeId and value in (:entries) returning value", nativeQuery = true)
@Query(value = "update dictionary_entry set deleted = false, version = :version where type_id = :typeId and value in (:entries) returning value", nativeQuery = true)
List<String> undeleteEntries(String typeId, Set<String> entries, long version);
}

View File

@ -30,6 +30,6 @@ public interface FalsePositiveEntryRepository extends JpaRepository<DictionaryFa
@Modifying
@Transactional
@Query(value = "update dictionary_false_positive_entry set deleted = true, version = :version where type_id = :typeId and value in (:entries) returning value", nativeQuery = true)
@Query(value = "update dictionary_false_positive_entry set deleted = false, version = :version where type_id = :typeId and value in (:entries) returning value", nativeQuery = true)
List<String> undeleteEntries(String typeId, Set<String> entries, long version);
}

View File

@ -33,6 +33,6 @@ public interface FalseRecommendationEntryRepository extends JpaRepository<Dictio
@Modifying
@Transactional
@Query(value = "update dictionary_false_recommendation_entry set deleted = true, version = :version where type_id = :typeId and value in (:entries) returning value", nativeQuery = true)
@Query(value = "update dictionary_false_recommendation_entry set deleted = false, version = :version where type_id = :typeId and value in (:entries) returning value", nativeQuery = true)
List<String> undeleteEntries(String typeId, Set<String> entries, long version);
}

View File

@ -309,4 +309,54 @@ public class DictionaryTest extends AbstractPersistenceServerServiceTest {
assertThat(actualEntries.size()).isEqualTo(0);
}
@Test
public void testAddEntries() {
var dossierTemplate = dossierTemplateTesterAndProvider.provideTestTemplate();
var type = Type.builder()
.type("dossier_redaction")
.label("Dossier Redactions")
.hexColor("#fcba03")
.rank(100)
.isHint(false)
.isCaseInsensitive(false)
.isRecommendation(false)
.description("Something")
.hasDictionary(true)
.addToDictionaryAction(false)
.dossierTemplateId(dossierTemplate.getId())
.build();
var createdType = dictionaryClient.addType(type);
var word1 = "Luke Skywalker";
var word2 = "Anakin Skywalker";
var word3 = "Yoda";
// Act & Assert: Add different words; All three should exist
var entries = new ArrayList<String>();
entries.add(word1);
entries.add(word2);
entries.add(word3);
dictionaryClient.addEntries(createdType.getTypeId(), entries, false, false, DictionaryEntryType.ENTRY);
var word4 = "Padme";
var word5 = "Obiwan";
entries.clear();
entries.add(word4);
entries.add(word5);
dictionaryClient.addEntries(createdType.getTypeId(), entries, true, false, DictionaryEntryType.ENTRY);
entries.add(word1);
entries.add(word2);
entries.add(word3);
dictionaryClient.addEntries(createdType.getTypeId(), entries, false, false, DictionaryEntryType.ENTRY);
var existingEntries = dictionaryClient.getEntriesForType(createdType.getTypeId(), 0L, DictionaryEntryType.ENTRY);
assertThat(existingEntries.stream().filter(f -> !f.isDeleted()).count()).isEqualTo(5);
}
}