I want to create a time tree for a calendar function - it works but I realize that it is very slow (1 insert per 20 seconds). Maybe anyone has a hint how the code shall be changed to gain more perofmance?
for ($calYear=2012;$calYear<2016; $calYear++)
{
$paramsYear =array(
"pYear" => $calYear,
"UUID" => uniqid()
);
$queryString = '
MERGE (y:calTime:calYear {name: {pYear}})
SET
y.uuid= {UUID},
y.created="'.time().'",
y.active="Y"
return y;
';
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString,$params);
$result = $query->getResultSet();
for ($calMonth=1;$calMonth<13; $calMonth++)
{
$paramsMonth =array(
"pYear" => $calYear,
"pMonth" => $calMonth,
"UUID" => uniqid()
);
$queryString = '
MATCH (y:calTime:calYear {name: {pYear}})
MERGE (m:calTime:calMonth {name: {pMonth}) -[:IS_MONTH_OF]->(y)
SET
m.uuid= {UUID},
m.created="'.time().'",
m.active="Y"
return m;
';
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString,$paramsMonth);
$result = $query->getResultSet();
$numberOfDays = date("t",mktime(0, 0, 0, $calMonth, 1, $calYear));
for ($calDay=1;$calDay<=$numberOfDays; $calDay++)
{
$paramsDay =array(
"pYear" => $calYear,
"pMonth" => $calMonth,
"pDay" => $calDay,
"UUID" => uniqid()
);
$queryString = '
MATCH (y:calTime:calYear {name: {pYear}) -- (m:calTime:calMonth {name: {pMonth})
MERGE (d:calTime:calDay {name: {pDay}) -[:IS_DAY_OF]->(m)
SET
d.uuid= {UUID},
d.created="'.time().'",
d.active="Y"
return d;
';
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString,$paramsDay);
$result = $query->getResultSet();
for ($calHour=1;$calHour<=24; $calHour++)
{
$paramsHour =array(
"pYear" => $calYear,
"pMonth" => $calMonth,
"pDay" => $calDay,
"pHour" => $calHour,
"UUID" => uniqid()
);
$queryString = '
MATCH (y:calTime:calYear {name: {pYear}) -- (m:calTime:calMonth {name: {pMonth}) -- (d:calTime:calDay {name: {pDay})
MERGE (h:calTime:calHour {name: {pHour}) -[:IS_HOUR_OF]->(d)
SET
h.uuid= {UUID},
h.created="'.time().'",
h.active="Y"
return h;
';
$query = new Everyman\Neo4j\Cypher\Query($client, $queryString,$paramsHour);
$result = $query->getResultSet();
} // End Hour
} // End Day
} // End Month
} // End Year