score:16
sorry for the late reply, we were busy building v2.8 ;) i would suggest to do as many things as possible on the database side, as copying and serializing/deserializing json over the network is typically expensive, so transferring as little data as possible should be a good aim.
first of all i have used your query and executed it on a sample dataset i created (~ 800 vertices and 800 edges are hit in my dataset) as a baseline i used the execution time of your query which in my case was ~5.0s
so i tried to create the exact same result as you need in aql only.
i have found some improvements in your query:
1. graph_neighbors
is a bit faster than graph_edges
.
2. if possible avoid {includedata: true}
if you do not need the data
especially if you need to/from vertices._id only graph_neighbors
with {includedata: false}
outperforms graph_edges
by an order of magnitude.
3. graph_neighbors is deduplicated, graph_edges is not. which in your case seems to be desired.
3. you can get rid of a couple of subqueries there.
so here is the pure aql query i could come up with:
let docid = "exampledocclass/1234567"
let edges = graph_edges('edgeclass',docid,{direction:'any',maxdepth:1,includedata:true})
let verticestmp = (for v in graph_neighbors('edgeclass', docid, {direction: 'any', maxdepth: 1, includedata: true})
return {
vertexdata: v,
outedges: graph_neighbors('edgeclass', v, {direction: 'outbound', maxdepth: 1, includedata: false}),
inedges: graph_neighbors('edgeclass', v, {direction: 'inbound', maxdepth: 1, includedata: false})
})
let vertices = push(verticestmp, {
vertexdata: document(docid),
outedges: graph_neighbors('edgeclass', docid, {direction: 'outbound', maxdepth: 1, includedata: false}),
inedges: graph_neighbors('edgeclass', docid, {direction: 'inbound', maxdepth: 1, includedata: false})
})
return { edges, vertices }
this yields the same result format as your query and has the advantage that every vertex connected to docid is stored exactly once in vertices. also docid itself is stored exactly once in vertices. no deduplication required on client side. but, in outedges / inedges of each vertices all connected vertices are also exactly once, i do not know if you need to know if there are multiple edges between vertices in this list as well.
this query uses ~0.06s on my dataset.
however if you put some more effort into it you could also consider to use a hand-crafted traversal inside a foxx application. this is a bit more complicated but might be faster in your case, as you do less subqueries. the code for this could look like the following:
var traversal = require("org/arangodb/graph/traversal");
var result = {
edges: [],
vertices: {}
}
var myvisitor = function (config, result, vertex, path, connected) {
switch (path.edges.length) {
case 0:
if (! result.vertices.hasownproperty(vertex._id)) {
// if we visit a vertex, we store it's data and prepare out/in
result.vertices[vertex._id] = {
vertexdata: vertex,
outedges: [],
inedges: []
};
}
// no further action
break;
case 1:
if (! result.vertices.hasownproperty(vertex._id)) {
// if we visit a vertex, we store it's data and prepare out/in
result.vertices[vertex._id] = {
vertexdata: vertex,
outedges: [],
inedges: []
};
}
// first depth, we need edgedata
var e = path.edges[0];
result.edges.push(e);
// we fill from / to for both vertices
result.vertices[e._from].outedges.push(e._to);
result.vertices[e._to].inedges.push(e._from);
break;
case 2:
// second depth, we do not need edgedata
var e = path.edges[1];
// we fill from / to for all vertices that exist
if (result.vertices.hasownproperty(e._from)) {
result.vertices[e._from].outedges.push(e._to);
}
if (result.vertices.hasownproperty(e._to)) {
result.vertices[e._to].inedges.push(e._from);
}
break;
}
};
var config = {
datasource: traversal.generalgraphdatasourcefactory("edgeclass"),
strategy: "depthfirst",
order: "preorder",
visitor: myvisitor,
expander: traversal.anyexpander,
mindepth: 0,
maxdepth: 2
};
var traverser = new traversal.traverser(config);
traverser.traverse(result, {_id: "exampledocclass/1234567"});
return {
edges: result.edges,
vertices: object.keys(result.vertices).map(function (key) {
return result.vertices[key];
})
};
the idea of this traversal is to visit all vertices from the start vertex to up to two edges away. all vertices in 0 - 1 depth will be added with data into the vertices object. all edges originating from the start vertex will be added with data into the edges list. all vertices in depth 2 will only set the outedges / inedges in the result.
this has the advantage that, vertices
is deduplicated. and outedges/inedges contain all connected vertices multiple times, if there are multiple edges between them.
this traversal executes on my dataset in ~0.025s so it is twice as fast as the aql only solution.
hope this still helps ;)
Source: stackoverflow.com
Related Query
- Getting data for d3 from ArangoDB using AQL (or arangojs)
- Getting data at run time, from a text box for example
- How do I Bind Data from a .tsv to an SVG's paths using d3.js for a Choropleth Map
- Getting data from JSON for D3.js
- D3 - loading xml data from file, using scales for barchart
- getting data for d3.js from mysql with php
- getting and using data from CSV file d3 v5
- Display Bar Chart for Last week, Last Month, and Last Year Data from JSON using D3.js
- Getting data from json file for D3 bubble chart
- Using data from Socket.io for data visualisation with d3
- Using an associative array as data for D3
- Importing data from .csv using d3.js
- Using Other Data Sources for cubism.js
- Can d3.js draw two scatterplots on the same graph using data from the same source?
- Using D3 transition method with data for scatter plot
- Loading local data for visualization using D3.js
- how to create labels for data in donut chart using d3.js
- How to load data from an internal JSON array rather than from an external resource / file for a collapsible tree in d3.js?
- Get data from rest service using D3
- Direct data input from Django for a D3 graph
- How to update elements of an HTML that the elements are created using data from a CSV file?
- Data for sunburst charts with d3.hierarchy using D3js v4
- D3js - Getting max value from d3.line() for a specific domain
- Create data visualizations using Express and get data from a PostgreSQL database
- Alternatives for using forEeach() loop while converting data for D3.js
- D3 linegraph using JSON data from API
- how to display bottom data for row chart using dc.js
- D3js - Getting a line chart drawn, from "JSON data" input using d3.json
- display data from csv file into BarGraph using d3.js
- Two bar charts from same data object using D3.js
More Query from same tag
- Get the object with the max value with D3
- How do I append DOM to an Angular 2 component and still get encapsulated styles
- C3.js SVG visualization to Canvas with canvg - Line charts filled with black rectangles , "ERROR: Element 'parsererror' not yet implemented"
- dc.js bubblechart colors scale is not working
- C3.js - Nested JSON objects, How to access and load data?
- D3 (v3.4) edge bundle chart and update button to load a new dataset
- Constraints on slider jquery + callng javascript function at page loadto call javascript function
- send query string via queue.defer
- Align multiple y-axes on the same chart in Billboard.js
- Create multinested JSON from URL in Javascript for d3.js
- d3.js tree layout compatibility with IE
- d3.js, using d3.extent to find min/max of nest json values
- How do I apply two svgs on one html page?
- In d3.js v4 zoom functionality I am having an issue where when i zoom out and then pan the chart goes out of the viewport instantly
- How to auto update sub elements datum binding in D3
- remove or skip null values in d3js stacked bar chart
- D3 and java script
- How to change D3js Gauge chart color, using update function?
- How to pass data to d3.json()
- Trying to add multiple D3 graphs
- Add data in pie chart using D3
- D3 javascript not running in html div
- How can I animate infinite marker movement down an SVG path without very high CPU usage?
- Unable to pass array value on YAxis in D3
- TopoJson makefile ignoring external properties file
- TopoJSON map not rendering properly using D3
- Scale of chart generated by using dc.js is returning NaN
- Changing the underlying data associated with a D3 selection?
- d3.js: Updating a pie with lables
- Show tool-tip on links of force directed graph in d3js