From 46b118175e7fbc559736dbfd0e3ea9783ac8881a Mon Sep 17 00:00:00 2001 From: Markus Date: Mon, 12 Oct 2020 14:40:48 +0200 Subject: [PATCH] Process names by rank then name. Start names index ids with 1, not 2 --- .../main/java/life/catalogue/db/mapper/NamesIndexMapper.java | 2 +- dao/src/main/java/life/catalogue/matching/NameIndexImpl.java | 2 -- .../main/resources/life/catalogue/db/mapper/NameMapper.xml | 2 +- .../resources/life/catalogue/db/mapper/NamesIndexMapper.xml | 4 ++-- dao/src/test/java/life/catalogue/db/TestDataRule.java | 2 +- .../java/life/catalogue/db/mapper/NamesIndexMapperTest.java | 3 +-- .../java/life/catalogue/release/StableIdProviderTest.java | 1 - 7 files changed, 6 insertions(+), 10 deletions(-) diff --git a/dao/src/main/java/life/catalogue/db/mapper/NamesIndexMapper.java b/dao/src/main/java/life/catalogue/db/mapper/NamesIndexMapper.java index 2a89933ebe..24183e812f 100644 --- a/dao/src/main/java/life/catalogue/db/mapper/NamesIndexMapper.java +++ b/dao/src/main/java/life/catalogue/db/mapper/NamesIndexMapper.java @@ -28,5 +28,5 @@ public interface NamesIndexMapper extends CRUD { /** * Resets the primary key sequence to the next highest int or 1 if no records exist. */ - void resetSequence(); + void updateSequence(); } diff --git a/dao/src/main/java/life/catalogue/matching/NameIndexImpl.java b/dao/src/main/java/life/catalogue/matching/NameIndexImpl.java index 2732fdc99d..b65c9e294d 100644 --- a/dao/src/main/java/life/catalogue/matching/NameIndexImpl.java +++ b/dao/src/main/java/life/catalogue/matching/NameIndexImpl.java @@ -278,8 +278,6 @@ public void reset() { NamesIndexMapper nim = session.getMapper(NamesIndexMapper.class); LOG.warn("Truncating the names index postgres table"); nim.truncate(); - LOG.info("Resetting names index sequence, count = {}", nim.count()); - nim.resetSequence(); } } diff --git a/dao/src/main/resources/life/catalogue/db/mapper/NameMapper.xml b/dao/src/main/resources/life/catalogue/db/mapper/NameMapper.xml index 01ca16d6bc..5915ccb8ef 100644 --- a/dao/src/main/resources/life/catalogue/db/mapper/NameMapper.xml +++ b/dao/src/main/resources/life/catalogue/db/mapper/NameMapper.xml @@ -354,7 +354,7 @@ SELECT FROM - ORDER BY rank + ORDER BY rank, scientific_name - TRUNCATE names_index + TRUNCATE names_index RESTART IDENTITY - + SELECT setval('names_index_id_seq', (SELECT COALESCE(max(id),1) FROM names_index)) diff --git a/dao/src/test/java/life/catalogue/db/TestDataRule.java b/dao/src/test/java/life/catalogue/db/TestDataRule.java index 85d5bc5baa..9c12f9709c 100644 --- a/dao/src/test/java/life/catalogue/db/TestDataRule.java +++ b/dao/src/test/java/life/catalogue/db/TestDataRule.java @@ -222,7 +222,7 @@ public void updateSequences() throws Exception { pm.updateIdSequences(testData.key); } // names index keys - session.getMapper(NamesIndexMapper.class).resetSequence(); + session.getMapper(NamesIndexMapper.class).updateSequence(); session.commit(); } diff --git a/dao/src/test/java/life/catalogue/db/mapper/NamesIndexMapperTest.java b/dao/src/test/java/life/catalogue/db/mapper/NamesIndexMapperTest.java index 290000e590..e6f974cdde 100644 --- a/dao/src/test/java/life/catalogue/db/mapper/NamesIndexMapperTest.java +++ b/dao/src/test/java/life/catalogue/db/mapper/NamesIndexMapperTest.java @@ -41,10 +41,9 @@ public void truncate() { mapper().truncate(); assertEquals(0, mapper().count()); - mapper().resetSequence(); IndexName n = createTestEntity(-1); mapper().create(n); - assertEquals(2, (int) n.getKey()); + assertEquals(1, (int) n.getKey()); } /** diff --git a/webservice/src/test/java/life/catalogue/release/StableIdProviderTest.java b/webservice/src/test/java/life/catalogue/release/StableIdProviderTest.java index e4e68eb3a9..1cb053e829 100644 --- a/webservice/src/test/java/life/catalogue/release/StableIdProviderTest.java +++ b/webservice/src/test/java/life/catalogue/release/StableIdProviderTest.java @@ -54,7 +54,6 @@ public void destroy() { } @Test - @Ignore public void run() throws Exception { provider.run(); try (SqlSession session = PgSetupRule.getSqlSessionFactory().openSession(true)) {