Skip to content

Commit

Permalink
Use 10 characters for medium hash. Use parent context for new id.
Browse files Browse the repository at this point in the history
  • Loading branch information
gunnarvelle committed Mar 12, 2024
1 parent d0dfe70 commit e96db97
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private Set<Context> createContexts(Node node) {
.flatMap(relevance -> Optional.of(
relevance.getPublicId().toString()))
.orElse("urn:relevance:core"),
HashUtil.semiHash(parentContext.rootId() + parentConnection.getPublicId()),
HashUtil.mediumHash(parentContext.contextId() + parentConnection.getPublicId()),
parentConnection.getRank(),
parentConnection.getPublicId().toString());
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/no/ndla/taxonomy/util/HashUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static String shortHash(Object original) {
}

public static String mediumHash(Object original) {
return generateHash(original, 8);
return generateHash(original, 10);
}

public static String semiHash(Object original) {
Expand Down
12 changes: 4 additions & 8 deletions src/test/java/no/ndla/taxonomy/rest/v1/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,10 @@ public void that_contexts_can_be_found_by_path() throws Exception {
.contentUri("urn:article:1")
.publicId("urn:resource:1"))));
Node resource = nodeRepository.getByPublicId(URI.create("urn:resource:1"));
String hash = HashUtil.semiHash(root.getPublicId().toString()
+ resource.getParentConnections().stream()
.findFirst()
.get()
.getPublicId()
.toString());

var response = testUtils.getResource("/v1/queries/path?path=" + String.format("/one-fine-resource__%s", hash));
var response = testUtils.getResource("/v1/queries/path?path="
+ String.format(
"/one-fine-resource__%s",
resource.getContexts().stream().findFirst().get().contextId()));
var result = testUtils.getObject(TaxonomyContextDTO[].class, response);

assertEquals(1, result.length);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/no/ndla/taxonomy/util/HashUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void get_different_length_hashes() {
String fullHash = HashUtil.fullHash("original");

assertEquals(4, shortHash.length());
assertEquals(8, mediumHash.length());
assertEquals(10, mediumHash.length());
assertEquals(12, semiHash.length());
assertEquals(16, longHash.length());
assertTrue(fullHash.length() > 16);
Expand Down

0 comments on commit e96db97

Please sign in to comment.