Skip to content

Commit

Permalink
Code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kennsippell committed Jun 23, 2023
1 parent a437ca7 commit c65602b
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions lib/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ var sanitise = function(string) {
return string.replace(/(\\+u0000)|\u0000/g, ''); // eslint-disable-line
};

const removeSecurityDetails = function(doc) {
const isUserDoc = doc && doc.type === 'user' && doc._id.startsWith('org.couchdb.user:');
if (isUserDoc) {
delete doc.password_scheme;
delete doc.derived_key;
delete doc.salt;
}
};

var deleteDocuments = function(db, postgresTable, docIdsToDelete) {
if (docIdsToDelete && docIdsToDelete.length) {
var query = format(DELETE_STMT, postgresTable, docIdsToDelete);
Expand Down Expand Up @@ -95,23 +104,13 @@ var loadAndStoreDocs = function(db, couchdb, concurrentDocLimit, docsToDownload,
}).then(function(couchDbResult) {
log.debug('Inserting ' + couchDbResult.rows.length + ' results into postgresql');

var insertSql = format(
INSERT_DOC_STMT,
postgresTable,
couchDbResult.rows.map(function(row) {
const isUserDoc = row.doc && row.doc.type === 'user' && row.doc._id.startsWith('org.couchdb.user:');
if (isUserDoc) {
delete row.doc.password_scheme;
delete row.doc.derived_key;
delete row.doc.salt;
}

return [row.doc];
})
);
const docsToInsert = couchDbResult.rows.map(function(row) {
removeSecurityDetails(row.doc);
return [row.doc];
});

let insertSql = format(INSERT_DOC_STMT, postgresTable, docsToInsert);
insertSql = sanitise(insertSql);

return db.query(insertSql);
}).then(function() {
return loadAndStoreDocs(db, couchdb, concurrentDocLimit, docsToDownload, postgresTable);
Expand Down

0 comments on commit c65602b

Please sign in to comment.