Skip to content

Commit

Permalink
feat(ref-imp): added timeout for fetaching operations of a DID
Browse files Browse the repository at this point in the history
  • Loading branch information
thehenrytsai committed Apr 9, 2021
1 parent 4cc7511 commit b840682
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/common/MongoDbStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import Logger from '../common/Logger';
* Base class that contains the common MongoDB collection setup.
*/
export default class MongoDbStore {

public static readonly defaultQueryTimeoutInMilliseconds = 10000;

/** MondoDB instance. */
protected db: Db | undefined;
/** MongoDB collection */
Expand Down
7 changes: 6 additions & 1 deletion lib/core/MongoDbOperationStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ export default class MongoDbOperationStore extends MongoDbStore implements IOper
* Gets all operations of the given DID unique suffix in ascending chronological order.
*/
public async get (didUniqueSuffix: string): Promise<AnchoredOperationModel[]> {
const mongoOperations = await this.collection!.find({ didSuffix: didUniqueSuffix }).sort({ txnNumber: 1, opIndex: 1 }).toArray();
const mongoOperations = await this.collection!
.find({ didSuffix: didUniqueSuffix })
.sort({ txnNumber: 1, opIndex: 1 })
.maxTimeMS(MongoDbStore.defaultQueryTimeoutInMilliseconds)
.toArray();

return mongoOperations.map((operation) => { return MongoDbOperationStore.convertToAnchoredOperationModel(operation); });
}

Expand Down

0 comments on commit b840682

Please sign in to comment.