Skip to content
Snippets Groups Projects
Commit f0ae9142 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

Merge branch 'fix/1440/optimize_certifiers_of' into 'dev'

[enh] Optimize BMA `/wot/certifiers-of/:search` and `/wot/certified-by/:search` - Close #1440

Closes #1440

See merge request !1423
parents 9a08389c 02f2118d
No related branches found
No related tags found
1 merge request!1423[enh] Optimize BMA `/wot/certifiers-of/:search` and `/wot/certified-by/:search` - Close #1440
Pipeline #31786 passed
...@@ -743,6 +743,17 @@ export class FileDAL implements ServerDAO { ...@@ -743,6 +743,17 @@ export class FileDAL implements ServerDAO {
return await this.iindexDAL.getFromPubkeyOrUid(search); return await this.iindexDAL.getFromPubkeyOrUid(search);
} }
async getWrittenIdtyByPubkeyForHashingAndIsMember(
pub: string
): Promise<{
uid: string;
created_on: string;
pub: string;
member: boolean;
} | null> {
return await this.iindexDAL.getFromPubkey(pub);
}
async getWrittenIdtyByPubkeyForRevocationCheck( async getWrittenIdtyByPubkeyForRevocationCheck(
pubkey: string pubkey: string
): Promise<{ ): Promise<{
......
...@@ -132,9 +132,16 @@ export class WOTBinding extends AbstractController { ...@@ -132,9 +132,16 @@ export class WOTBinding extends AbstractController {
async certifiersOf(req: any): Promise<HttpCertifications> { async certifiersOf(req: any): Promise<HttpCertifications> {
const search = await ParametersService.getSearchP(req); const search = await ParametersService.getSearchP(req);
const idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember( let idty: FullIindexEntry;
search if (req.query.pubkey) {
)) as FullIindexEntry; idty = (await this.server.dal.getWrittenIdtyByPubkeyForHashingAndIsMember(
search
)) as FullIindexEntry;
} else {
idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember(
search
)) as FullIindexEntry;
}
const certs = await this.server.dal.certsToTarget( const certs = await this.server.dal.certsToTarget(
idty.pub, idty.pub,
IdentityDTO.getTargetHash(idty) IdentityDTO.getTargetHash(idty)
...@@ -229,9 +236,16 @@ export class WOTBinding extends AbstractController { ...@@ -229,9 +236,16 @@ export class WOTBinding extends AbstractController {
async certifiedBy(req: any): Promise<HttpCertifications> { async certifiedBy(req: any): Promise<HttpCertifications> {
const search = await ParametersService.getSearchP(req); const search = await ParametersService.getSearchP(req);
const idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember( let idty: FullIindexEntry;
search if (req.query.pubkey) {
)) as FullIindexEntry; idty = (await this.server.dal.getWrittenIdtyByPubkeyForHashingAndIsMember(
search
)) as FullIindexEntry;
} else {
idty = (await this.server.dal.getWrittenIdtyByPubkeyOrUIdForHashingAndIsMember(
search
)) as FullIindexEntry;
}
const certs = await this.server.dal.certsFrom(idty.pub); const certs = await this.server.dal.certsFrom(idty.pub);
const theCerts: HttpCertification[] = []; const theCerts: HttpCertification[] = [];
for (const cert of certs) { for (const cert of certs) {
......
...@@ -192,6 +192,13 @@ describe("Identities collision", function() { ...@@ -192,6 +192,13 @@ describe("Identities collision", function() {
}); });
}); });
it('should have certifiers-of/:pubkey of cat giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
res.should.have.property('uid').equal('cat');
});
});
it('should have certifiers-of/tic giving results', function() { it('should have certifiers-of/tic giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/tic', { json: true }), function(res:HttpCertifications) { return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/tic', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV'); res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV');
...@@ -213,6 +220,13 @@ describe("Identities collision", function() { ...@@ -213,6 +220,13 @@ describe("Identities collision", function() {
}); });
}); });
it('should have certifiers-of/:pubkey of tic giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV');
res.should.have.property('uid').equal('tic');
});
});
it('should have certifiers-of/toc giving results', function() { it('should have certifiers-of/toc giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/toc', { json: true }), function(res:HttpCertifications) { return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/toc', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo'); res.should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo');
...@@ -234,6 +248,13 @@ describe("Identities collision", function() { ...@@ -234,6 +248,13 @@ describe("Identities collision", function() {
}); });
}); });
it('should have certifiers-of/:pubkey of toc giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certifiers-of/DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DKpQPUL4ckzXYdnDRvCRKAm1gNvSdmAXnTrJZ7LvM5Qo');
res.should.have.property('uid').equal('toc');
});
});
it('requirements of cat', function() { it('requirements of cat', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/requirements/cat', { json: true }), function(res:HttpRequirements) { return expectAnswer(rp('http://127.0.0.1:7799/wot/requirements/cat', { json: true }), function(res:HttpRequirements) {
res.should.have.property('identities').be.an.Array; res.should.have.property('identities').be.an.Array;
...@@ -298,6 +319,13 @@ describe("Identities collision", function() { ...@@ -298,6 +319,13 @@ describe("Identities collision", function() {
}); });
}); });
it('should have certified-by/:pubkey of tic giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('DNann1Lh55eZMEDXeYt59bzHbA3NJR46DeQYCS2qQdLV');
res.should.have.property('uid').equal('tic');
});
});
it('should have certified-by/tac giving results', function() { it('should have certified-by/tac giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/tac', { json: true }), function(res:HttpCertifications) { return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/tac', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc'); res.should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
...@@ -308,6 +336,13 @@ describe("Identities collision", function() { ...@@ -308,6 +336,13 @@ describe("Identities collision", function() {
}); });
}); });
it('should have certified-by/:pubkey of tac giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('2LvDg21dVXvetTD9GdkPLURavLYEqP3whauvPWX4c2qc');
res.should.have.property('uid').equal('tac');
});
});
it('should have certified-by/cat giving results', function() { it('should have certified-by/cat giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/cat', { json: true }), function(res:HttpCertifications) { return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/cat', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd'); res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
...@@ -343,6 +378,13 @@ describe("Identities collision", function() { ...@@ -343,6 +378,13 @@ describe("Identities collision", function() {
}); });
}); });
it('should have certified-by/:pubkey of cat giving results', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/certified-by/HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd?pubkey', { json: true }), function(res:HttpCertifications) {
res.should.have.property('pubkey').equal('HgTTJLAQ5sqfknMq7yLPZbehtuLSsKj9CxWN7k8QvYJd');
res.should.have.property('uid').equal('cat');
});
});
it('requirements of man2', function() { it('requirements of man2', function() {
return expectAnswer(rp('http://127.0.0.1:7799/wot/requirements/man2', { json: true }), function(res:HttpRequirements) { return expectAnswer(rp('http://127.0.0.1:7799/wot/requirements/man2', { json: true }), function(res:HttpRequirements) {
res.should.have.property('identities').be.an.Array; res.should.have.property('identities').be.an.Array;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment