prepare to async: trivial reformatting

This change is only cosmetic. Its aim is do make it easier to understand the
async changes that are going to be merged later on. It was extracted from the
original work from Ray Bellis.

To verify that nothing has changed, you can run the following command on each
file touched by this commit:
  npm install uglify-es
  diff --unified <(uglify-js --beautify bracketize <BEFORE.js>) <(uglify-js --beautify bracketize <AFTER.js>)



This is a complete script that does the same automatically (works from a
mercurial clone):

```bash
#!/usr/bin/env bash

set -eu

REVISION=<THIS_REVISION>

PARENT_REV=$(hg identify --rev "${REVISION}" --template '{p1rev}')
FILE_LIST=$(hg status --no-status --change ${REVISION})
UGLIFYJS="node_modules/uglify-es/bin/uglifyjs"

for FILE_NAME in ${FILE_LIST[@]}; do
  echo "Checking ${FILE_NAME}"
  diff --unified \
    <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${PARENT_REV}" "${FILE_NAME}")) \
    <("${UGLIFYJS}" --beautify bracketize <(hg cat --rev "${REVISION}"   "${FILE_NAME}"))
done
```
This commit is contained in:
muxator 2019-02-08 23:20:57 +01:00
parent cc23bd18a4
commit 9497ee734f
33 changed files with 2706 additions and 2943 deletions

View file

@ -18,57 +18,56 @@ var log4js = require('log4js');
var async = require("async");
var db = require("../db/DB").db;
exports.setPadRaw = function(padId, records, callback){
exports.setPadRaw = function(padId, records, callback)
{
records = JSON.parse(records);
async.eachSeries(Object.keys(records), function(key, cb){
var value = records[key]
async.eachSeries(Object.keys(records), function(key, cb) {
var value = records[key];
if(!value){
if (!value) {
return setImmediate(cb);
}
// Author data
if(value.padIDs){
// rewrite author pad ids
if (value.padIDs) {
// Author data - rewrite author pad ids
value.padIDs[padId] = 1;
var newKey = key;
// Does this author already exist?
db.get(key, function(err, author){
if(author){
// Yes, add the padID to the author..
if( Object.prototype.toString.call(author) === '[object Array]'){
db.get(key, function(err, author) {
if (author) {
// Yes, add the padID to the author
if (Object.prototype.toString.call(author) === '[object Array]') {
author.padIDs.push(padId);
}
value = author;
}else{
} else {
// No, create a new array with the author info in
value.padIDs = [padId];
}
});
// Not author data, probably pad data
}else{
// we can split it to look to see if its pad data
} else {
// Not author data, probably pad data
// we can split it to look to see if it's pad data
var oldPadId = key.split(":");
// we know its pad data..
if(oldPadId[0] === "pad"){
// we know it's pad data
if (oldPadId[0] === "pad") {
// so set the new pad id for the author
oldPadId[1] = padId;
// and create the value
var newKey = oldPadId.join(":"); // create the new key
}
}
// Write the value to the server
db.set(newKey, value);
setImmediate(cb);
}, function(){
},
function() {
callback(null, true);
});
}