• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 22572052718

02 Mar 2026 10:33AM UTC coverage: 25.19% (+0.1%) from 25.064%
22572052718

push

github

ashleycaselli
chore(logging): add logging messages for MongoDB index initialization and element retrieval

125 of 586 branches covered (21.33%)

Branch coverage included in aggregate %.

471 of 1780 relevant lines covered (26.46%)

4.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.04
src/main/java/com/knowledgepixels/registry/db/IndexInitializer.java
1
package com.knowledgepixels.registry.db;
2

3
import com.knowledgepixels.registry.Collection;
4
import com.mongodb.client.ClientSession;
5
import com.mongodb.client.model.IndexOptions;
6
import com.mongodb.client.model.Indexes;
7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
import static com.knowledgepixels.registry.RegistryDB.collection;
11
import static com.mongodb.client.model.Indexes.*;
12

13
/**
14
 * Initializes indexes for MongoDB collections used in the application.
15
 */
16
public final class IndexInitializer {
×
17

18
    private static final Logger logger = LoggerFactory.getLogger(IndexInitializer.class);
12✔
19

20
    /**
21
     * Initializes indexes for the main MongoDB collections.
22
     *
23
     * @param mongoSession the client session for MongoDB operations
24
     */
25
    public static void initCollections(ClientSession mongoSession) {
26
        logger.info("Initializing MongoDB indexes for main collections...");
9✔
27
        final IndexOptions unique = new IndexOptions().unique(true);
18✔
28

29
        collection(Collection.TASKS.toString()).createIndex(mongoSession, Indexes.descending("not-before"));
39✔
30

31
        collection(Collection.NANOPUBS.toString()).createIndex(mongoSession, ascending("fullId"), unique);
42✔
32
        collection(Collection.NANOPUBS.toString()).createIndex(mongoSession, descending("counter"), unique);
42✔
33
        collection(Collection.NANOPUBS.toString()).createIndex(mongoSession, ascending("pubkey"));
39✔
34

35
        collection("lists").createIndex(mongoSession, ascending("pubkey", "type"), unique);
51✔
36
        collection("lists").createIndex(mongoSession, ascending("status"));
36✔
37

38
        collection("listEntries").createIndex(mongoSession, ascending("np"));
36✔
39
        collection("listEntries").createIndex(mongoSession, ascending("pubkey", "type", "np"), unique);
63✔
40
        collection("listEntries").createIndex(mongoSession, compoundIndex(ascending("pubkey"), ascending("type"), descending("position")), unique);
117✔
41
        collection("listEntries").createIndex(mongoSession, ascending("pubkey", "type", "checksum"), unique);
63✔
42
        collection("listEntries").createIndex(mongoSession, ascending("invalidated"));
36✔
43

44
        collection("invalidations").createIndex(mongoSession, ascending("invalidatingNp"));
36✔
45
        collection("invalidations").createIndex(mongoSession, ascending("invalidatingPubkey"));
36✔
46
        collection("invalidations").createIndex(mongoSession, ascending("invalidatedNp"));
36✔
47
        collection("invalidations").createIndex(mongoSession, ascending("invalidatingPubkey", "invalidatedNp"));
48✔
48

49
        collection("trustEdges").createIndex(mongoSession, ascending("fromAgent"));
36✔
50
        collection("trustEdges").createIndex(mongoSession, ascending("fromPubkey"));
36✔
51
        collection("trustEdges").createIndex(mongoSession, ascending("toAgent"));
36✔
52
        collection("trustEdges").createIndex(mongoSession, ascending("toPubkey"));
36✔
53
        collection("trustEdges").createIndex(mongoSession, ascending("source"));
36✔
54
        collection("trustEdges").createIndex(mongoSession, ascending("fromAgent", "fromPubkey", "toAgent", "toPubkey", "source"), unique);
87✔
55
        collection("trustEdges").createIndex(mongoSession, ascending("invalidated"));
36✔
56

57
        collection("hashes").createIndex(mongoSession, ascending("hash"), unique);
39✔
58
        collection("hashes").createIndex(mongoSession, ascending("value"), unique);
39✔
59
    }
3✔
60

61
    /**
62
     * Initializes indexes for loading-related MongoDB collections.
63
     */
64
    public static void initLoadingCollections(ClientSession mongoSession) {
65
        logger.info("Initializing MongoDB indexes for loading collections...");
9✔
66
        final IndexOptions unique = new IndexOptions().unique(true);
18✔
67

68
        collection("endorsements_loading").createIndex(mongoSession, ascending("agent"));
36✔
69
        collection("endorsements_loading").createIndex(mongoSession, ascending("pubkey"));
36✔
70
        collection("endorsements_loading").createIndex(mongoSession, ascending("endorsedNanopub"));
36✔
71
        collection("endorsements_loading").createIndex(mongoSession, ascending("source"));
36✔
72
        collection("endorsements_loading").createIndex(mongoSession, ascending("status"));
36✔
73
        // zip: Hmm, not possible to set com.mongodb.client.model.WriteModel<T> here
74
        // I'd currently recommend to have a package with the DB related stuff
75
        // and therein a Custom Extension T of <Document>, where we could put that WriteModel<T>.
76

77
        collection("agents_loading").createIndex(mongoSession, ascending("agent"), unique);
39✔
78
        collection("agents_loading").createIndex(mongoSession, descending("accountCount"));
36✔
79
        collection("agents_loading").createIndex(mongoSession, descending("avgPathCount"));
36✔
80
        collection("agents_loading").createIndex(mongoSession, descending("totalRatio"));
36✔
81

82
        collection("accounts_loading").createIndex(mongoSession, ascending("agent"));
36✔
83
        collection("accounts_loading").createIndex(mongoSession, ascending("pubkey"));
36✔
84
        collection("accounts_loading").createIndex(mongoSession, ascending("agent", "pubkey"), unique);
51✔
85
        collection("accounts_loading").createIndex(mongoSession, ascending("type"));
36✔
86
        collection("accounts_loading").createIndex(mongoSession, ascending("status"));
36✔
87
        collection("accounts_loading").createIndex(mongoSession, descending("ratio"));
36✔
88
        collection("accounts_loading").createIndex(mongoSession, descending("pathCount"));
36✔
89

90
        collection("trustPaths_loading").createIndex(mongoSession, ascending("agent", "pubkey", "depth", "sorthash"), unique);
75✔
91
        collection("trustPaths_loading").createIndex(mongoSession, ascending("depth"));
36✔
92
        collection("trustPaths_loading").createIndex(mongoSession, descending("ratio"));
36✔
93
    }
3✔
94

95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc