-
Notifications
You must be signed in to change notification settings - Fork 94
/
description.js
executable file
·155 lines (123 loc) · 4.27 KB
/
description.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
'use strict';
var arangojs = require('arangojs');
var opts = {
maxSockets: 25,
keepAlive: true,
keepAliveMsecs: 1000
};
var Agent = require('http').Agent;
module.exports = {
name: 'ArangoDB',
startup: function (host, cb) {
var db = new arangojs.Database({
url: 'http://' + host + ':8529',
agent: new Agent(opts),
fullDocument: false
});
cb(db);
},
warmup: function (db, cb) {
module.exports.getCollection(db, 'profiles', function (err, coll) {
if (err) return cb(err);
module.exports.aggregate(db, coll, function (err, result) {
if (err) return cb(err);
console.log('INFO step 1/3 done');
module.exports.getCollection(db, 'relations', function (err, coll2) {
if (err) return cb(err);
db.route('_api/collection/relations/loadIndexesIntoMemory').put(function (err, result) {
if (err) return cb(err);
console.log('INFO step 2/3 done');
var warmupIds = require('../data/warmup1000');
var goal = 1000;
var total = 0;
for (var i = 0; i < goal; i++) {
module.exports.getDocument(db, coll, warmupIds[i], function (err, result) {
if (err) return cb(err);
++total;
if (total === goal) {
console.log('INFO step 3/3 done');
console.log('INFO warmup done');
return cb(null);
}
});
}
});
});
});
});
},
getCollection: function (db, name, cb) {
cb(undefined, db.collection(name));
},
dropCollection: function (db, name, cb) {
db.collection(name).drop(cb);
},
createCollection: function (db, name, cb) {
db.collection(name).create(cb);
},
createCollectionSync: function (db, name, cb) {
db.collection(name).create({waitForSync: true}, cb);
},
getDocument: function (db, coll, id, cb) {
coll.document(id, cb);
},
saveDocument: function (db, coll, doc, cb) {
coll.save(doc, cb);
},
saveDocumentSync: function (db, coll, doc, cb) {
coll.save(doc, cb);
},
aggregate: function (db, coll, cb) {
db.query('FOR x IN ' + coll.name + ' COLLECT age = x.AGE WITH COUNT INTO counter RETURN {age: age, amount: counter}', cb);
},
aggregate2: function (db, coll, coll2, cb) {
db.query('LET tmp = (FOR y IN ' + coll.name + ' FOR x IN ' + coll2.name + ' FILTER x._from == CONCAT("' + coll.name + '", y._key) OR x._to == CONCAT("' + coll.name + '", y._key) COLLECT a=1 WITH COUNT INTO counter RETURN {amount: counter}) RETURN LENGTH(tmp)', cb);
},
neighbors: function (db, collP, collR, id, i, cb) {
db.query('FOR v IN OUTBOUND @key ' + collR.name + ' OPTIONS {bfs: true, uniqueVertices: "global"} RETURN v._id',
{key: collP.name + '/' + id},
function (err, result) {
if (err) return cb(err);
result.all(function (err, v) {
if (err) return cb(err);
cb(null, v.length);
});
}
);
},
neighbors2: function (db, collP, collR, id, i, cb) {
db.query('FOR v IN 1..2 OUTBOUND @key ' + collR.name + ' OPTIONS {bfs: true, uniqueVertices: "global"} RETURN v._id',
{key: collP.name + '/' + id},
function (err, result) {
if (err) return cb(err);
result.all(function (err, v) {
if (err) return cb(err);
cb(null, v.length);
});
}
);
},
neighbors2data: function (db, collP, collR, id, i, cb) {
db.query('FOR v IN 1..2 OUTBOUND @key ' + collR.name + ' OPTIONS {bfs: true, uniqueVertices: "global"} RETURN v',
{key: collP.name + '/' + id},
function (err, result) {
if (err) return cb(err);
result.all(function (err, v) {
if (err) return cb(err);
cb(null, v.length);
});
}
);
},
shortestPath: function (db, collP, collR, path, i, cb) {
db.query('FOR v IN OUTBOUND SHORTEST_PATH @from TO @to ' + collR.name + ' RETURN v._id',
{from: 'profiles/' + path.from, to: 'profiles/' + path.to}, function (err, result) {
if (err) return cb(err);
result.all(function (err, v) {
if (err) return cb(err);
cb(null, (v.length === 0) ? 0 : (v.length - 1));
});
}
);
}
};