-
Notifications
You must be signed in to change notification settings - Fork 23
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
Elastic Integration (Phase II) #339
Conversation
…as the overrideClient for elastic
…into internal-mappings
…into internal-mappings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
two comments, but 👍
@@ -305,9 +334,11 @@ exports.getComponentPackage = control.memoize(getComponentPackage); | |||
exports.isDirectory = control.memoize(isDirectory); | |||
exports.tryRequire = control.memoize(tryRequire); | |||
exports.readFilePromise = control.memoize(readFilePromise); | |||
exports.getFilesPromise = control.memoize(getFilesPromise); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference between this and readFilePromise
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
readFilePromise
returns the contents of a file, getFilesPromise
is like getFiles
in that it returns all the filenames within a directory. I just needed to have a version of getFiles
which returned a Promise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhhh makes sense
// * | ||
// * @return {Promise} | ||
// */ | ||
// function createInternalIndices() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented out...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can remove this from this PR, but this function will be included in the next phase of changes whenever we actually instantiate the indices that are managed by Amphora.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, then it's cool to leave it in there
@jonwinton yeah, but that's not a breaking change in amphora's api, is it? You could still technically init that stuff in your clay instance (though you don't need to anymore) |
@jonwinton @nelsonpecora I'd think that's a breaking change to |
@jonwinton In the feature list: |
Ah, sorry about that @gloddy. I've updated the original message. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Just some minor comments and questions.
*/ | ||
function filterRefs(op) { | ||
_.each(_.listDeepObjects(op, refProp), function (obj) { | ||
console.log(op[refProp]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.log
helpful in prd?
* @param {string} propertyName | ||
* @returns {Function} | ||
*/ | ||
function removeEmptyValuesForProperty(propertyName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this get used anywhere? Popped into my head when I saw this: https://github.com/nymag/amphora/pull/339/files#diff-6612bbbf33f2f172a7fe9e466fbfff28R214
@@ -339,17 +313,59 @@ function batch(ops) { | |||
} | |||
|
|||
/** | |||
* Create the ES Client or an empty object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment not helpful anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fixed, but it's not showing up here...Proof: https://github.com/nymag/amphora/blob/internal-mappings/lib/services/search.js#L316
// Create client + check the connection | ||
return createClient(overrideClient) | ||
.then(healthCheck) | ||
// .then(createInternalIndices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holding this here for the next iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
@@ -339,17 +313,59 @@ function batch(ops) { | |||
} | |||
|
|||
/** | |||
* Create the ES Client or an empty object | |||
* [createClient description] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete?
*/ | ||
function filterRefs(op) { | ||
_.each(_.listDeepObjects(op, refProp), function (obj) { | ||
console.log(op[refProp]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be logged? If so, could use winston.
* @returns {boolean} | ||
*/ | ||
function isOpForPage(op) { | ||
return op.key.indexOf('/pages/') > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
op.key
always a string? Could JSDoc that. Function name could be shortened to isPageOp
.
* @returns {boolean} | ||
*/ | ||
function isOpForInstance(op) { | ||
return op.key.indexOf('/instances/') > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
/** | ||
* True is component is published ("@published") | ||
* @param {object} op | ||
* @returns {boolean} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@param {string} op.key
?
expect(fn(op)).to.equal(true); | ||
}); | ||
|
||
it('takes an operation and returns false if its key is\'nt a page ref', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn\'t
or is not
-- might want to search replace for this
function compare(expected) { | ||
return function (comparison) { | ||
return expected === comparison; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrow function could be nice here return comparison => expected === comparison;
function resolveReferencesForPropertyOfStringType(propertyName) { | ||
return function (ops) { | ||
return bluebird.all(_.map(ops, function (op) { | ||
var result, value = op.value[propertyName]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
always will be an op.value object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yessir!
|
||
_.each(ops, function (op) { | ||
if (_.isString(op.value)) { | ||
op.value = JSON.parse(op.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
op.value is always an object or JSON string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yessir!
* @returns {Promise} | ||
*/ | ||
function validateIndices(mappings) { | ||
return bluebird.all(_.map(Object.keys(mappings), function (index) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use native map since Object.keys is always an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lodash _.map
is still faster than native map because it uses a for loop, plus it maps to the patterns that we've already established. I'd prefer to leave it until there's a good performance reason to switch them all over.
return createClient(overrideClient) | ||
.then(healthCheck) | ||
// .then(createInternalIndices) | ||
.then(setupMappings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does overrideDir get passed through?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overrideClient
? It can be, but really it's only used in testing. The comment is updated to address this.
+1 |
This PR Includes Breaking Changes
New Features:
elastic
which contains helpers for parsing batch operations from the database. Directory will also house the mappings internal to Amphora (coming soon)On The Implementation Side:
search
at the root of your instance and implement a more robust system of parsing data for ES. See example of implementation here.