mirror of https://gitee.com/bigwinds/arangodb
fixed WeakDictionary
This commit is contained in:
parent
10761c616e
commit
dab85633dd
|
@ -1,6 +1,6 @@
|
|||
module.define("org/arangodb/graph", function(exports, module) {
|
||||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, plusplus: true */
|
||||
/*global require, WeakDictionary, exports */
|
||||
/*global require, exports */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Graph functionality
|
||||
|
@ -1218,9 +1218,9 @@ function Graph(name, vertices, edges) {
|
|||
this._vertices = vertices;
|
||||
this._edges = edges;
|
||||
|
||||
// and weak dictionary for vertices and edges
|
||||
this._weakVertices = new WeakDictionary();
|
||||
this._weakEdges = new WeakDictionary();
|
||||
// and dictionary for vertices and edges
|
||||
this._verticesCache = {};
|
||||
this._edgesCache = {};
|
||||
|
||||
// and store the cashes
|
||||
this.predecessors = {};
|
||||
|
@ -1812,10 +1812,10 @@ Graph.prototype.normalizedMeasurement = function (measurement) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype.constructVertex = function (id) {
|
||||
var vertex = this._weakVertices[id];
|
||||
var vertex = this._verticesCache[id];
|
||||
|
||||
if (vertex === undefined) {
|
||||
this._weakVertices[id] = vertex = new Vertex(this, id);
|
||||
this._verticesCache[id] = vertex = new Vertex(this, id);
|
||||
}
|
||||
|
||||
return vertex;
|
||||
|
@ -1826,10 +1826,10 @@ Graph.prototype.constructVertex = function (id) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype.constructEdge = function (id) {
|
||||
var edge = this._weakEdges[id];
|
||||
var edge = this._edgesCache[id];
|
||||
|
||||
if (edge === undefined) {
|
||||
this._weakEdges[id] = edge = new Edge(this, id);
|
||||
this._edgesCache[id] = edge = new Edge(this, id);
|
||||
}
|
||||
|
||||
return edge;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, plusplus: true */
|
||||
/*global require, WeakDictionary, exports */
|
||||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, white: true, plusplus: true */
|
||||
/*global require, exports */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Graph functionality
|
||||
|
@ -51,7 +51,8 @@ var findOrCreateCollectionByName = function (name) {
|
|||
|
||||
if (col === null) {
|
||||
col = db._create(name);
|
||||
} else if (! (col instanceof ArangoCollection) || col.type() != ArangoCollection.TYPE_DOCUMENT) {
|
||||
}
|
||||
else if (!(col instanceof ArangoCollection) || col.type() !== ArangoCollection.TYPE_DOCUMENT) {
|
||||
throw "<" + name + "> must be a document collection";
|
||||
}
|
||||
|
||||
|
@ -71,7 +72,8 @@ var findOrCreateEdgeCollectionByName = function (name) {
|
|||
|
||||
if (col === null) {
|
||||
col = db._createEdgeCollection(name);
|
||||
} else if (!(col instanceof ArangoCollection) || col.type() != ArangoCollection.TYPE_EDGE) {
|
||||
}
|
||||
else if (!(col instanceof ArangoCollection) || col.type() !== ArangoCollection.TYPE_EDGE) {
|
||||
throw "<" + name + "> must be an edge collection";
|
||||
}
|
||||
|
||||
|
@ -218,11 +220,11 @@ Edge.prototype.getOutVertex = function () {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Edge.prototype.getPeerVertex = function (vertex) {
|
||||
if (vertex._id == this._properties._to) {
|
||||
if (vertex._id === this._properties._to) {
|
||||
return this._graph.constructVertex(this._properties._from);
|
||||
}
|
||||
|
||||
if (vertex._id == this._properties._from) {
|
||||
if (vertex._id === this._properties._from) {
|
||||
return this._graph.constructVertex(this._properties._to);
|
||||
}
|
||||
|
||||
|
@ -669,7 +671,7 @@ Vertex.prototype.commonNeighborsWith = function (target_vertex, options) {
|
|||
return neighbor.id;
|
||||
};
|
||||
|
||||
if (typeof(target_vertex) != 'object') {
|
||||
if (typeof(target_vertex) !== 'object') {
|
||||
throw "<target_vertex> must be a vertex object";
|
||||
}
|
||||
|
||||
|
@ -680,10 +682,12 @@ Vertex.prototype.commonNeighborsWith = function (target_vertex, options) {
|
|||
|
||||
if ((options.listed !== undefined) && (options.listed === true)) {
|
||||
return_value = common_neighbors;
|
||||
} else if ((options.normalized !== undefined) && (options.normalized === true)) {
|
||||
}
|
||||
else if ((options.normalized !== undefined) && (options.normalized === true)) {
|
||||
all_neighbors = neighbor_set_one.unite(neighbor_set_two);
|
||||
return_value = (common_neighbors.length / all_neighbors.length);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return_value = common_neighbors.length;
|
||||
}
|
||||
|
||||
|
@ -736,7 +740,7 @@ Vertex.prototype.commonPropertiesWith = function (other_vertex, options) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Vertex.prototype.pathTo = function (target_vertex, options) {
|
||||
if (typeof(target_vertex) != 'object') {
|
||||
if (typeof(target_vertex) !== 'object') {
|
||||
throw "<target_vertex> must be an object";
|
||||
}
|
||||
var predecessors = target_vertex.determinePredecessors(this, options || {});
|
||||
|
@ -1169,7 +1173,8 @@ function Graph(name, vertices, edges) {
|
|||
|
||||
try {
|
||||
graphProperties = gdb.document(name);
|
||||
} catch (e) {
|
||||
}
|
||||
catch (e1) {
|
||||
graphProperties = null;
|
||||
}
|
||||
|
||||
|
@ -1217,9 +1222,9 @@ function Graph(name, vertices, edges) {
|
|||
this._vertices = vertices;
|
||||
this._edges = edges;
|
||||
|
||||
// and weak dictionary for vertices and edges
|
||||
this._weakVertices = new WeakDictionary();
|
||||
this._weakEdges = new WeakDictionary();
|
||||
// and dictionary for vertices and edges
|
||||
this._verticesCache = {};
|
||||
this._edgesCache = {};
|
||||
|
||||
// and store the cashes
|
||||
this.predecessors = {};
|
||||
|
@ -1381,16 +1386,19 @@ Graph.prototype.getVertex = function (id) {
|
|||
|
||||
try {
|
||||
ref = this._vertices.document(id);
|
||||
} catch (e) {
|
||||
}
|
||||
catch (e) {
|
||||
ref = null;
|
||||
}
|
||||
|
||||
if (ref !== null) {
|
||||
vertex = this.constructVertex(ref._id);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
try {
|
||||
vertex = this.constructVertex(id);
|
||||
} catch (e) {
|
||||
}
|
||||
catch (e1) {
|
||||
vertex = null;
|
||||
}
|
||||
}
|
||||
|
@ -1484,7 +1492,7 @@ Graph.prototype.getEdge = function (id) {
|
|||
} else {
|
||||
try {
|
||||
edge = this.constructEdge(id);
|
||||
} catch (e) {
|
||||
} catch (e1) {
|
||||
edge = null;
|
||||
}
|
||||
}
|
||||
|
@ -1811,10 +1819,10 @@ Graph.prototype.normalizedMeasurement = function (measurement) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype.constructVertex = function (id) {
|
||||
var vertex = this._weakVertices[id];
|
||||
var vertex = this._verticesCache[id];
|
||||
|
||||
if (vertex === undefined) {
|
||||
this._weakVertices[id] = vertex = new Vertex(this, id);
|
||||
this._verticesCache[id] = vertex = new Vertex(this, id);
|
||||
}
|
||||
|
||||
return vertex;
|
||||
|
@ -1825,10 +1833,10 @@ Graph.prototype.constructVertex = function (id) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Graph.prototype.constructEdge = function (id) {
|
||||
var edge = this._weakEdges[id];
|
||||
var edge = this._edgesCache[id];
|
||||
|
||||
if (edge === undefined) {
|
||||
this._weakEdges[id] = edge = new Edge(this, id);
|
||||
this._edgesCache[id] = edge = new Edge(this, id);
|
||||
}
|
||||
|
||||
return edge;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*jslint indent: 2, nomen: true, maxlen: 100, sloppy: true, vars: true, white: true, plusplus: true, stupid: true */
|
||||
/*global require, exports */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief version check at the start of the server, will optionally perform
|
||||
|
@ -61,7 +62,7 @@
|
|||
|
||||
function collectionExists (name) {
|
||||
var collection = getCollection(name);
|
||||
return (collection != undefined) && (collection != null) && (collection.name() == name);
|
||||
return (collection !== undefined) && (collection !== null) && (collection.name() === name);
|
||||
}
|
||||
|
||||
function createSystemCollection (name, attributes) {
|
||||
|
@ -70,7 +71,7 @@
|
|||
}
|
||||
|
||||
var realAttributes = attributes || { };
|
||||
realAttributes['isSystem'] = true;
|
||||
realAttributes.isSystem = true;
|
||||
|
||||
if (db._create(name, realAttributes)) {
|
||||
return true;
|
||||
|
@ -98,7 +99,7 @@
|
|||
// VERSION file exists, read its contents
|
||||
var versionInfo = internal.read(versionFile);
|
||||
|
||||
if (versionInfo != '') {
|
||||
if (versionInfo !== '') {
|
||||
var versionValues = JSON.parse(versionInfo);
|
||||
|
||||
if (versionValues && versionValues.version && ! isNaN(versionValues.version)) {
|
||||
|
@ -111,7 +112,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
console.log("Starting upgrade from version " + (lastVersion || "unknown") + " to " + internal.db._version());
|
||||
console.log("Starting upgrade from version " + (lastVersion || "unknown")
|
||||
+ " to " + internal.db._version());
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// the actual upgrade tasks. all tasks defined here should be "re-entrant"
|
||||
|
@ -123,16 +125,18 @@
|
|||
});
|
||||
|
||||
// create a unique index on username attribute in _users
|
||||
addTask("createUsersIndex", "create index on username attribute in _users collection", function () {
|
||||
var users = getCollection("_users");
|
||||
if (! users) {
|
||||
return false;
|
||||
}
|
||||
addTask("createUsersIndex",
|
||||
"create index on username attribute in _users collection",
|
||||
function () {
|
||||
var users = getCollection("_users");
|
||||
if (! users) {
|
||||
return false;
|
||||
}
|
||||
|
||||
users.ensureUniqueConstraint("username");
|
||||
users.ensureUniqueConstraint("username");
|
||||
|
||||
return true;
|
||||
});
|
||||
return true;
|
||||
});
|
||||
|
||||
// add a default root user with no passwd
|
||||
addTask("addDefaultUser", "add default root user", function () {
|
||||
|
@ -141,7 +145,7 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
if (users.count() == 0) {
|
||||
if (users.count() === 0) {
|
||||
// only add account if user has not created his/her own accounts already
|
||||
users.save({ user: "root", password: internal.encodePassword(""), active: true });
|
||||
}
|
||||
|
@ -155,67 +159,72 @@
|
|||
});
|
||||
|
||||
// create a unique index on name attribute in _graphs
|
||||
addTask("createGraphsIndex", "create index on name attribute in _graphs collection", function () {
|
||||
var graphs = getCollection("_graphs");
|
||||
addTask("createGraphsIndex",
|
||||
"create index on name attribute in _graphs collection",
|
||||
function () {
|
||||
var graphs = getCollection("_graphs");
|
||||
|
||||
if (! graphs) {
|
||||
return false;
|
||||
}
|
||||
|
||||
graphs.ensureUniqueConstraint("name");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// make distinction between document and edge collections
|
||||
addTask("addCollectionVersion", "set new collection type for edge collections and update collection version", function () {
|
||||
var collections = db._collections();
|
||||
|
||||
for (var i in collections) {
|
||||
var collection = collections[i];
|
||||
|
||||
try {
|
||||
if (collection.version() > 1) {
|
||||
// already upgraded
|
||||
continue;
|
||||
}
|
||||
|
||||
if (collection.type() == 3) {
|
||||
// already an edge collection
|
||||
collection.setAttribute("version", 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (collection.count() > 0) {
|
||||
var isEdge = true;
|
||||
// check the 1st 50 documents from a collection
|
||||
var documents = collection.ALL(0, 50);
|
||||
|
||||
for (var j in documents) {
|
||||
var doc = documents[j];
|
||||
|
||||
// check if documents contain both _from and _to attributes
|
||||
if (! doc.hasOwnProperty("_from") || ! doc.hasOwnProperty("_to")) {
|
||||
isEdge = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isEdge) {
|
||||
collection.setAttribute("type", 3);
|
||||
console.log("made collection '" + collection.name() + " an edge collection");
|
||||
}
|
||||
}
|
||||
collection.setAttribute("version", 2);
|
||||
}
|
||||
catch (e) {
|
||||
console.error("could not upgrade collection '" + collection.name() + "'");
|
||||
if (! graphs) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
graphs.ensureUniqueConstraint("name");
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// make distinction between document and edge collections
|
||||
addTask("addCollectionVersion",
|
||||
"set new collection type for edge collections and update collection version",
|
||||
function () {
|
||||
var collections = db._collections();
|
||||
var i;
|
||||
|
||||
for (i in collections) {
|
||||
var collection = collections[i];
|
||||
|
||||
try {
|
||||
if (collection.version() > 1) {
|
||||
// already upgraded
|
||||
continue;
|
||||
}
|
||||
|
||||
if (collection.type() == 3) {
|
||||
// already an edge collection
|
||||
collection.setAttribute("version", 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (collection.count() > 0) {
|
||||
var isEdge = true;
|
||||
// check the 1st 50 documents from a collection
|
||||
var documents = collection.ALL(0, 50);
|
||||
|
||||
for (var j in documents) {
|
||||
var doc = documents[j];
|
||||
|
||||
// check if documents contain both _from and _to attributes
|
||||
if (! doc.hasOwnProperty("_from") || ! doc.hasOwnProperty("_to")) {
|
||||
isEdge = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isEdge) {
|
||||
collection.setAttribute("type", 3);
|
||||
console.log("made collection '" + collection.name() + " an edge collection");
|
||||
}
|
||||
}
|
||||
collection.setAttribute("version", 2);
|
||||
}
|
||||
catch (e) {
|
||||
console.error("could not upgrade collection '" + collection.name() + "'");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
// create the _modules collection
|
||||
addTask("createModules", "setup _modules collection", function () {
|
||||
|
|
Loading…
Reference in New Issue