Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

feat: Added GetBulkAsRawMap function to the MongoDB API #259

Merged
merged 1 commit into from
Jun 8, 2022

Conversation

bstasyszyn
Copy link
Contributor

GetBulkAsRawMap returns a slice of 'raw' maps, one for each of the specified keys.

Also exposed PrepareFilter and CreateMongoDBFindOptions so that clients may prepare queries for use with the QueryCustom function.

Signed-off-by: Bob Stasyszyn [email protected]

GetBulkAsRawMap returns a slice of 'raw' maps, one for each of the specified keys.

Also exposed PrepareFilter and CreateMongoDBFindOptions so that clients may prepare queries for use with the QueryCustom function.

Signed-off-by: Bob Stasyszyn <[email protected]>
@codecov
Copy link

codecov bot commented Jun 8, 2022

Codecov Report

Merging #259 (1457bfd) into main (55b4fab) will increase coverage by 2.41%.
The diff coverage is 66.66%.

❗ Current head 1457bfd differs from pull request most recent head be0461a. Consider uploading reports for the commit be0461a to get more accurate results

@@            Coverage Diff             @@
##             main     #259      +/-   ##
==========================================
+ Coverage   85.82%   88.23%   +2.41%     
==========================================
  Files          26        1      -25     
  Lines        3992      799    -3193     
==========================================
- Hits         3426      705    -2721     
+ Misses        334       52     -282     
+ Partials      232       42     -190     
Impacted Files Coverage Δ
component/storage/mongodb/store.go 88.23% <66.66%> (-1.74%) ⬇️
...nt/vdr/trustbloc/config/signatureconfig/helpers.go
...vdr/trustbloc/selection/staticselection/service.go
...omponent/vdr/trustbloc/didconfiguration/helpers.go
component/storage/mysql/store.go
...nt/vdr/trustbloc/config/verifyingconfig/service.go
component/vdr/orb/internal/ldcontext/ldcontext.go
component/vdr/trustbloc/endpoint/service.go
component/vdr/sidetree/option.go
... and 17 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 55b4fab...be0461a. Read the comment docs.

@fqutishat fqutishat merged commit ac003b2 into hyperledger-archives:main Jun 8, 2022
@bstasyszyn bstasyszyn deleted the mongodb-2 branch June 8, 2022 17:30
ctxWithTimeout, cancel := context.WithTimeout(context.Background(), s.timeout)
defer cancel()

for cursor.Next(ctxWithTimeout) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to note here: since this context is getting reused, all the cursor.Next calls need to complete before the timeout. Might be an issue if there's a large result set.

I see that I also did the same thing in the collectBulkGetResults method. Perhaps it's not urgent right now, but might be worth reworking in the future to use a new context for each call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something to note here: since this context is getting reused, all the cursor.Next calls need to complete before the timeout. Might be an issue if there's a large result set.

I see that I also did the same thing in the collectBulkGetResults method. Perhaps it's not urgent right now, but might be worth reworking in the future to use a new context for each call.

It depends on how timeout is defined. If timeout is defined as the timeout for the entire function, i.e. GetBulk, then this is correct. Otherwise, you'd have a variable timeout for GetBulk depending on how many items in the result set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I probably need to define the timeout more explicitly. Right now here's how I defined it above the WithTimeout function:

// WithTimeout is an option for specifying the timeout for all calls to MongoDB.
// The timeout is 10 seconds by default.

When I created that option, I was thinking the timeout was per remote call to MongoDB (which a cursor.Next would be, depending on the current page). So far in the other areas of the code, I create a new timeout for every possible MongoDB call (with the exception of the bulk results collection as mentioned above). But I now see a problem with that approach. Some calls to MongoDB can take longer than others (e.g. some Find calls that execute queries). I think ideally the caller should be able to pass in their own timeout to each call, which is tricky with the current interface. I think I should create a followup issue for me to address this in the future. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, ideally the caller should be providing the context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #262

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants