{"action":"created","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/11995","repository_url":"https://api.github.com/repos/phalcon/cphalcon","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11995/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11995/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11995/events","html_url":"https://github.com/phalcon/cphalcon/issues/11995","id":166448496,"number":11995,"title":"Upgrade from 1.x to 2.x has broken code with models magic getters/setters","user":{"login":"TrogWarZ","id":5672868,"avatar_url":"https://avatars.githubusercontent.com/u/5672868?v=3","gravatar_id":"","url":"https://api.github.com/users/TrogWarZ","html_url":"https://github.com/TrogWarZ","followers_url":"https://api.github.com/users/TrogWarZ/followers","following_url":"https://api.github.com/users/TrogWarZ/following{/other_user}","gists_url":"https://api.github.com/users/TrogWarZ/gists{/gist_id}","starred_url":"https://api.github.com/users/TrogWarZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TrogWarZ/subscriptions","organizations_url":"https://api.github.com/users/TrogWarZ/orgs","repos_url":"https://api.github.com/users/TrogWarZ/repos","events_url":"https://api.github.com/users/TrogWarZ/events{/privacy}","received_events_url":"https://api.github.com/users/TrogWarZ/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/phalcon/cphalcon/labels/Bug%20-%20Medium","name":"Bug - Medium","color":"d7e102"}],"state":"open","locked":false,"assignee":{"login":"andresgutierrez","id":213590,"avatar_url":"https://avatars.githubusercontent.com/u/213590?v=3","gravatar_id":"","url":"https://api.github.com/users/andresgutierrez","html_url":"https://github.com/andresgutierrez","followers_url":"https://api.github.com/users/andresgutierrez/followers","following_url":"https://api.github.com/users/andresgutierrez/following{/other_user}","gists_url":"https://api.github.com/users/andresgutierrez/gists{/gist_id}","starred_url":"https://api.github.com/users/andresgutierrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andresgutierrez/subscriptions","organizations_url":"https://api.github.com/users/andresgutierrez/orgs","repos_url":"https://api.github.com/users/andresgutierrez/repos","events_url":"https://api.github.com/users/andresgutierrez/events{/privacy}","received_events_url":"https://api.github.com/users/andresgutierrez/received_events","type":"User","site_admin":false},"assignees":[{"login":"andresgutierrez","id":213590,"avatar_url":"https://avatars.githubusercontent.com/u/213590?v=3","gravatar_id":"","url":"https://api.github.com/users/andresgutierrez","html_url":"https://github.com/andresgutierrez","followers_url":"https://api.github.com/users/andresgutierrez/followers","following_url":"https://api.github.com/users/andresgutierrez/following{/other_user}","gists_url":"https://api.github.com/users/andresgutierrez/gists{/gist_id}","starred_url":"https://api.github.com/users/andresgutierrez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andresgutierrez/subscriptions","organizations_url":"https://api.github.com/users/andresgutierrez/orgs","repos_url":"https://api.github.com/users/andresgutierrez/repos","events_url":"https://api.github.com/users/andresgutierrez/events{/privacy}","received_events_url":"https://api.github.com/users/andresgutierrez/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/phalcon/cphalcon/milestones/19","html_url":"https://github.com/phalcon/cphalcon/milestones/3.0.1","labels_url":"https://api.github.com/repos/phalcon/cphalcon/milestones/19/labels","id":1850807,"number":19,"title":"3.0.1","description":"","creator":{"login":"sergeyklay","id":1256298,"avatar_url":"https://avatars.githubusercontent.com/u/1256298?v=3","gravatar_id":"","url":"https://api.github.com/users/sergeyklay","html_url":"https://github.com/sergeyklay","followers_url":"https://api.github.com/users/sergeyklay/followers","following_url":"https://api.github.com/users/sergeyklay/following{/other_user}","gists_url":"https://api.github.com/users/sergeyklay/gists{/gist_id}","starred_url":"https://api.github.com/users/sergeyklay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergeyklay/subscriptions","organizations_url":"https://api.github.com/users/sergeyklay/orgs","repos_url":"https://api.github.com/users/sergeyklay/repos","events_url":"https://api.github.com/users/sergeyklay/events{/privacy}","received_events_url":"https://api.github.com/users/sergeyklay/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":21,"state":"open","created_at":"2016-06-27T16:06:25Z","updated_at":"2016-08-16T19:05:02Z","due_on":null,"closed_at":null},"comments":11,"created_at":"2016-07-19T22:05:35Z","updated_at":"2016-08-16T19:40:19Z","closed_at":null,"body":"## Prerequisites\r\n\r\n* Ubuntu 12.04.x/14.x\r\n* PHP 5.5.x/5.6.x (from `ppa:ondrej/php` and from deprecated `ppa:ondrej/php5-5.6` too)\r\n* Transformers from [thephpleague/fractal package](https://github.com/thephpleague/fractal)\r\n* Each API response contains mostly 100 objects + 3 connected objects (total 400 minus duplicates)\r\n* [XhProf](https://github.com/gajus/xhprof.io) as profiler\r\n\r\n## Phalcon 1.3.x (tested mostly on 1.3.6)\r\n\r\nAPI response less than 1 second, about 5-7 megabytes RAM. XhProf shows that slowest point is `\\file_exists` in composer autoload. Cool, fast.\r\n\r\n## Phalcon 2.x (tested mostly on 2.0.10)\r\n\r\nStrange happens. API response 40-60 seconds, very huge RAM eating (1 gigabyte and more plus swap), 100% eats one CPU core.\r\n\r\nXhProf shows that bottleneck is `\\ReflectionClass::getProperty` and traces leading to `\\Phalcon\\Mvc\\Model\\Resultset\\Simple::current`. After some digging into, i found that PR #11417 made my code totally broken. Callgraph attached at the end of this post.\r\n\r\n## Workaround\r\n\r\nAs a workaround i can extend magic setter of model in my base model and copy-paste some code from sources like this:\r\n\r\n```php\r\npublic function __set($property, $value)\r\n{\r\n    if (is_array($value) || is_object($value))\r\n        return parent::__set($property, $value);\r\n\r\n    if ($this->_possibleSetter($property, $value))\r\n        return $value();\r\n\r\n    $this->{$property} = $value;\r\n\r\n    return $value();\r\n}\r\n```\r\n\r\nBut, i think, this is a crooked nail. In my company and projects, we use only setters/getters for models and repos and don't care about setting like `$model->someprop = 'foobar'` (thus, it's not affects `toArray` call behaviour).\r\n\r\n## Questions\r\n\r\n1. Why it uses **very slow** Reflection instead of `getModelsMetadata` (that **can be cached**!)?\r\n2. Really need caching of metadata here that got from Reflection. Can it be done? I can make PR for this but i have no experience with Zephir and time for this will be very huge (only in first part of august, maybe).\r\n3. Can i update Phalcon later to LTS version and be **sure** that it (workaround, i mean) won't broke anything?\r\n\r\nThanks for any suggestions.\r\n\r\n## Callgraph\r\n\r\n![callgraph](https://cloud.githubusercontent.com/assets/5672868/16968369/73cd6568-4e1f-11e6-986d-caf867cef55c.png)\r\n"},"comment":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/comments/240214320","html_url":"https://github.com/phalcon/cphalcon/issues/11995#issuecomment-240214320","issue_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11995","id":240214320,"user":{"login":"TrogWarZ","id":5672868,"avatar_url":"https://avatars.githubusercontent.com/u/5672868?v=3","gravatar_id":"","url":"https://api.github.com/users/TrogWarZ","html_url":"https://github.com/TrogWarZ","followers_url":"https://api.github.com/users/TrogWarZ/followers","following_url":"https://api.github.com/users/TrogWarZ/following{/other_user}","gists_url":"https://api.github.com/users/TrogWarZ/gists{/gist_id}","starred_url":"https://api.github.com/users/TrogWarZ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TrogWarZ/subscriptions","organizations_url":"https://api.github.com/users/TrogWarZ/orgs","repos_url":"https://api.github.com/users/TrogWarZ/repos","events_url":"https://api.github.com/users/TrogWarZ/events{/privacy}","received_events_url":"https://api.github.com/users/TrogWarZ/received_events","type":"User","site_admin":false},"created_at":"2016-08-16T19:40:19Z","updated_at":"2016-08-16T19:40:19Z","body":"@andresgutierrez, am i doing it right?\r\n\r\n```bash\r\ngit clone git://github.com/phalcon/cphalcon.git /tmp/cphalcon\r\ncd /tmp/cphalcon/build\r\ngit checkout 3.0.x\r\n./install\r\nservice php5.6-fpm restart\r\nphp -r \"echo Phalcon\\Version::get();\"\r\n```"}}
{"actor":{"display_login":"TrogWarZ"}}