Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bulkDelete_underscoreAPI.js and count_underscoreAPI.js to stored procedures samples #5

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

dwhieb
Copy link

@dwhieb dwhieb commented Aug 28, 2016

No description provided.

@dwhieb
Copy link
Author

dwhieb commented Sep 13, 2016

Just following up - any movement on this PR? Thanks!

@rnagpal
Copy link

rnagpal commented Sep 13, 2016

@dwhieb : Sorry for the delay. I've asked the respective owners to take a look at it.

@dwhieb
Copy link
Author

dwhieb commented Sep 13, 2016

No worries - thanks!

@emilylawton
Copy link
Member

Thanks, @dwhieb! These samples are great. Our bank of stored procedure samples currently includes Count.js which performs a document count with an optional filter and bulkDelete.js which deletes documents for a given query. What additional functionality did you want to add with clear.js and length.js?

@dwhieb
Copy link
Author

dwhieb commented Sep 14, 2016

Well for both sprocs I added the option to pass a key and value to filter on. And for count.js I used the collection's .filter() method, which seemed a little more straightforward since I was in fact filtering.

I'd be happy to incorporate these changes into the sprocs already in the repo if that'd be better. And in retrospect I think passing a filter object rather than two arguments would be a better way to structure the filter option.

@koltachev
Copy link

Thanks for reaching out!
I think since these are using underscore API it would make sense to keep them this way.
There is a couple of issues which is not a big deal -- I'll add a few comments.

@@ -0,0 +1,121 @@
/**

Choose a reason for hiding this comment

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

Can this be renamed to bulkDelete_underscoreAPI.js to make it clear this is similar to bulkDelete.js but using underscore API?

Copy link
Author

Choose a reason for hiding this comment

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

};

// filter the collection for sessions using the filter function
const accepted = __.filter(filter, { continuation: continuationToken }, handler);

Choose a reason for hiding this comment

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

Perf: the predicate function needs to be inlined in order to take advantage of index (otherwise it will be full scan).

Copy link
Author

Choose a reason for hiding this comment

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

/**
* A stored procedure for Azure DocumentDB which gets a count of the session documents using the .filter() method of the collection.
* @function
* @param {String} filterOn = 'type' The key to filter documents on for deletion.

Choose a reason for hiding this comment

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

Should say for counting instead of deletion.

Copy link
Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,90 @@
/**

Choose a reason for hiding this comment

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

Can this be renamed to count_underscoreAPI.js to make it clear this is similar to count.js but using underscore API?

Copy link
Author

Choose a reason for hiding this comment

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

};

// filter the collection for sessions using the filter function
const accepted = __.filter(filter, { continuation: continuationToken }, handler);

Choose a reason for hiding this comment

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

Perf: the predicate function needs to be inlined in order to take advantage of index (otherwise it will be full scan).

Copy link
Author

Choose a reason for hiding this comment

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


}

module.exports = length;

Choose a reason for hiding this comment

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

I don't think module is currently supported (will be soon).

Copy link
Author

Choose a reason for hiding this comment

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

* @param {String} info.continuation The continuation token, if any was passed
* @return {responseBody}
*/
const handler = function handler(err, sessions, info) {

Choose a reason for hiding this comment

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

Can we rename 'sessions' parameter to something more generic, like docs, or documents, or docFeed?

Copy link
Author

Choose a reason for hiding this comment

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

/**
* Recursively deletes each session in an array, and then attempts to get more to delete
* @function
* @param {Array} sessions The array of session documents to delete

Choose a reason for hiding this comment

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

can we rename sessions for function name and function parameter to more generic? Like deleteDocuments etc.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link

@koltachev koltachev left a comment

Choose a reason for hiding this comment

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

Thanks for reaching out! Let's fix a couple of issues..

@dwhieb
Copy link
Author

dwhieb commented Sep 15, 2016

Great! I'll tackle these changes now.

@dwhieb
Copy link
Author

dwhieb commented Sep 15, 2016

@koltachev Ok I've added my revisions to the PR and addressed each of your comments (I noted the commit for each), as well as changed the way the filter parameter is structured, so that the sprocs now take a single (optional) filter object as an argument.

@dwhieb dwhieb changed the title add clear.js and length.js to stored procedures samples add bulkDelete_underscoreAPI.js and count_underscoreAPI.js to stored procedures samples Sep 16, 2016
Copy link
Contributor

@mkolt mkolt left a comment

Choose a reason for hiding this comment

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

Please see comments...

// NB: The filter function must be inlined in order to take advantage of index
// (otherwise it will be a full scan).
const accepted = __.filter(function filter(doc) {
return Object.keys(filterObj).every(function checkProperty(filterKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Function calls are not yet supported for optimized index, so this will work but again, will be full scan - slow. This scenario will work when we have __.where implemented. For now, I guess, let's change the sample to the version it was before -- simple filtering by property name and property value passed from outside.

Copy link
Author

Choose a reason for hiding this comment

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

* @param {String} info.continuation The continuation token, if any was passed
* @return {responseBody}
*/
const handler = function handler(err, docs, info) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this to filterHandler to be more explicit?

Copy link
Author

Choose a reason for hiding this comment

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

* @param {String} info.continuation The continuation token, if any was passed
* @return {responseBody}
*/
const handler = function handler(err, docs, info) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we change this to filterHandler to be more explicit? Same for the count sproc.

Copy link
Author

Choose a reason for hiding this comment

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

// NB: The filter function must be inlined in order to take advantage of index
// (otherwise it will be a full scan).
const accepted = __.filter(function filter(doc) {
return Object.keys(filterObj).every(function checkProperty(filterKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Function calls are not yet supported for optimized index, so this will work but again, will be full scan - slow. This scenario will work when we have __.where implemented. For now, I guess, let's change the sample to the version it was before -- simple filtering by property name and property value passed from outside. Same for the count sproc.

Copy link
Author

Choose a reason for hiding this comment

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

@dwhieb
Copy link
Author

dwhieb commented Sep 16, 2016

@mkolt Should be all set!

@@ -1,59 +1,59 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file getting modified? Looks like it's not. Can we remove if it from the change?

@@ -1,66 +1,66 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this file getting modified? Looks like it's not. Can we remove if it from the change?

@@ -1,26 +1,26 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the change need to modify this file?

// filter the collection for documents using the filter object
const accepted = __.filter(function filter(doc) {

if (filterValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry :) Same perf issue. For optimized index, function calls and if-statements are currently not supported. How about if we change it to be like this: return filterKey === undefined || doc[filterKey] === doc[filterValue];
And same for the other sample...

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

Successfully merging this pull request may close these issues.

5 participants