I am trying to create an api controller for my application. The general idea is based on the post data I have a parent class I look up inthe database and create a new child and save it. This works well initally but if there is a second post the response is extremely slow.
class ApiController extends ControllerBase
{
public function initialize()
{
$this->tag->setTitle('API');
parent::initialize();
}
public function startAction(){
$this->view->disable();
$this->setJsonResponse();
if($this->request->isPost()){
$data = $this->request;
if($data != null){
$json = file_get_contents('php://input');
$obj = json_decode($json);
$id = $obj->parent_id;
$message = "message: " . $obj->parent_id;
$conditions = "serialid = :serialid:";
$parameters = array(
"serialid" => $id
);
$parent = Parent::findFirst(array(
$conditions,
"bind" => $parameters));
if($parent != null){
$child = new Child();
$child->parent_id = $parent->id;
$child->uuid = $obj->event_id;
$child->timestamp = date("Y-m-d H:m:s", $obj->simestamp);
if ($child->save() == false) {
return json_encode(array("result" => "ERROR: failed Attempt"));
} else {
return json_encode(array("result" => "SUCCESS"));
}
}else{
return json_encode(array("result" => "ERROR: parent not found" , "Message" => $message));
}
}else{
return json_encode(array("result" => "ERROR: No data received"));
}
}else{
return json_encode(array("result" => "ERROR: Needs to be Post"));
}
}
}