Skip to content

Commit

Permalink
fix: refine tag search + remove tryPermanodeThanNode function
Browse files Browse the repository at this point in the history
  • Loading branch information
brancoder committed May 5, 2023
1 parent 7900e8e commit 23753ba
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 59 deletions.
7 changes: 6 additions & 1 deletion api/src/utils/stardust/searchQueryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,12 @@ export class SearchQueryBuilder {
}

// also perform a tag search
tag = Converter.utf8ToHex(this.query, true);
const maybeTag = Converter.isHex(this.query, true) ?
HexHelper.addPrefix(this.query) :
Converter.utf8ToHex(this.query, true);
if (maybeTag.length < 66) {
tag = maybeTag;
}
}

return {
Expand Down
58 changes: 0 additions & 58 deletions api/src/utils/stardust/stardustTangleHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,64 +586,6 @@ export class StardustTangleHelper {
).run();
}

/**
* Generic helper function to try fetching from permanode client (if configured).
* On failure (or not present), we try to fetch from node.
* @param args The argument(s) to pass to the fetch calls.
* @param methodName The function to call on the client.
* @param network The network config in context.
* @param isIndexerCall The boolean flag for indexer api instead of core api.
* @returns The results or null if call(s) failed.
*/
public static async tryFetchPermanodeThenNode<A, R>(
args: A,
methodName: string,
network: INetwork,
isIndexerCall: boolean = false
): Promise<R> | null {
const {
provider, user, password, permaNodeEndpoint,
permaNodeEndpointUser, permaNodeEndpointPassword, disableApiFallback
} = network;
const isFallbackEnabled = !disableApiFallback;

if (permaNodeEndpoint) {
const permanode = !isIndexerCall ?
new SingleNodeClient(
permaNodeEndpoint,
{ userName: permaNodeEndpointUser, password: permaNodeEndpointPassword }
) :
new IndexerPluginClient(
new SingleNodeClient(
permaNodeEndpoint,
{ userName: permaNodeEndpointUser, password: permaNodeEndpointPassword }
)
);

try {
// try fetch from permanode (chronicle)
const result: Promise<R> = permanode[methodName](args);
return await result;
} catch { }
}

if (!permaNodeEndpoint || isFallbackEnabled) {
const node = !isIndexerCall ?
new SingleNodeClient(provider, { userName: user, password }) :
new IndexerPluginClient(
new SingleNodeClient(provider, { userName: user, password })
);

try {
// try fetch from node
const result: Promise<R> = node[methodName](args);
return await result;
} catch { }
}

return null;
}

/**
* Generic helper function to try fetching from node client.
* On failure (or not present), we try to fetch from permanode (if configured).
Expand Down

0 comments on commit 23753ba

Please sign in to comment.