{"id":398452,"date":"2024-06-29T14:05:00","date_gmt":"2024-06-29T14:05:00","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=398452"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=398452","title":{"rendered":"<span>\u041e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u044d\u043a\u0435\u043d\u0434\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u043d\u0430 Symfony. \u0427\u0430\u0441\u0442\u044c 2<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e! <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u0433\u0434\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c entity manager, unit of work, bulk inserts \u0438 batching processing \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u043d\u0430\u0439\u0442\u0438 \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445.<\/p>\n<p>\u0412<a href=\"https:\/\/habr.com\/ru\/articles\/729360\/\" rel=\"noopener noreferrer nofollow\"> \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 n+1, \u0432\u0438\u0434\u0430\u0445 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445. \u0422\u0430\u043c \u0436\u0435 \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0441\u0445\u0435\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/strong> &#8212; \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u0438 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u043b\u0438 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u044b, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435, \u0447\u0442\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043c\u043e\u0439 \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439.<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e Unit of Work \u0438 EntityManager<\/h2>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 ORM, \u0432\u0430\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0432\u0441\u0435\u043c\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u043d\u0430\u0434 \u044d\u0442\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 Doctrine \u044d\u0442\u0438\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f EntityManager.<\/p>\n<p>EntityManager (em) &#8212; \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 ORM, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. EntityManager \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a Doctrine \u0438 \u043a \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u0435\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: Unit of Work, Identity Map \u0438 Transactional write-behind.<\/p>\n<p><a href=\"https:\/\/www.martinfowler.com\/eaaCatalog\/unitOfWork.html\" rel=\"noopener noreferrer nofollow\">Unit of Work<\/a> (uow) &#8212; \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 ORM \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f), \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438. \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438 \u0434\u0440.), \u043e\u043d\u0438 \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0442\u0441\u044f <a href=\"https:\/\/www.doctrine-project.org\/projects\/doctrine-orm\/en\/2.14\/reference\/events.html#onflush\" rel=\"noopener noreferrer nofollow\">(NEW,MANAGED,DETACHED, REMOVED)<\/a> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043b\u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 Unit of Work. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 flush() \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>IdentityMap \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 ORM, \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443.<\/p>\n<p>Transactional write-behind &#8212; \u0441\u0443\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0438 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 flush()).<\/p>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0430\u0441\u0442\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f em.<\/p>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/strong><\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 EntityManager \u0438 UnitOfWork, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 &#171;New&#187; . \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 persist(), Doctrine \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 &#171;Managed&#187;, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 (ScheduledEntityInsertions) \u0438 \u0432 IdentityMap. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 flush() \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:     <\/p>\n<pre><code class=\"php\">\/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044c\u0435\u043a\u0442 $category = new Category(); $category->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 1'); \/\/ \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043d\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 EntityManager \u0438 UnitOfWork  dump('IdentityMap \u0434\u043e persist', $em->getUnitOfWork()->getIdentityMap()); \/\/ \u041e\u0431\u044c\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 UnitOfWork (IdentityMap \u0438 ScheduledEntityInsertions) $em->persist($category); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 persist', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 persist', $em->getUnitOfWork()->getScheduledEntityInsertions()); \/\/ \u041e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0434, \u0430\u043a\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 UnitOfWork, \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 ScheduledEntityInsertions $em->flush(); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 flush', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 flush', $em->getUnitOfWork()->getScheduledEntityInsertions());<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u0434\u043e persist\": [] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 persist\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25b6] ] \"ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 persist\" array:1 [\u25bc   1325 => App\\Entity\\Category {#1325 \u25b6} ] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 flush\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25b6] ] \"ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 flush\" [] \"SQL \u0437\u0430\u043f\u0440\u043e\u0441\" \"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2510   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 1\" ] \"COMMIT\"<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 Transactional write-behind. \u041c\u044b \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0438\u0445 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"php\">\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438  $cat2 = new Category(); $cat2->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2'); $cat3 = new Category(); $cat3->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3'); \/\/ \u041d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f $em->persist($cat2); $em->persist($cat3); \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u043c \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"SQL \u0437\u0430\u043f\u0440\u043e\u0441\" \"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2512   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ] INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2513   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3\" ] \"COMMIT\" <\/code><\/pre>\n<p>\u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0431\u0434 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432) \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"php\">$cat2 = new Category(); $cat2->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2'); $cat3 = new Category(); $cat3->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3'); $em->persist($cat2); $em->flush(); $em->persist($cat3); $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2521   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ] \"COMMIT\" \"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2522   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3\" ] \"COMMIT\"<\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/strong><\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, Doctrine \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 IdentityMap, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 &#171;Managed&#187; \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0438\u0437 \u0431\u0434 . \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0435\u0449\u0435 \u0440\u0430\u0437, Doctrine \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 IdentityMap. <\/p>\n<pre><code class=\"php\">dump('\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u0434\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->size()); \/\/ \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c $category1 = $em->getRepository(Category::class) ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2']); \/\/ \u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c $category2 = $em->getRepository(Category::class) ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2']); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->getIdentityMap()); dump('\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->size()); dump('$category1 === $category2', $category1 === $category2); <\/code><\/pre>\n<pre><code class=\"sql\">\"\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u0434\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" 0 \"IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     5 => App\\Entity\\Category {#1286 \u25bc       -id: 5       -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\"       -places: Doctrine\\ORM\\PersistentCollection {#1059 \u25b6}     }   ] ] \"\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" 1 \"$category1 === $category2\" true \"SQL \u0437\u0430\u043f\u0440\u043e\u0441\" SELECT t0.id AS id_1, t0.title AS title_2 FROM category t0 WHERE t0.title = ? LIMIT 1 Parameters: [\u25bc   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ] View formatted query    View runnable query    Explain query 20.87 ms SELECT t0.id AS id_1, t0.title AS title_2 FROM category t0 WHERE t0.title = ? LIMIT 1 Parameters: [\u25bc   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ]<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 IdentityMap, \u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 find() Doctrine \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 findBy, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445), \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 IdentityMap.<\/p>\n<pre><code class=\"php\">\/\/ \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c $category1 = $em->getRepository(Category::class) ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2']); \/\/ \u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c find $category2 = $em->getRepository(Category::class) ->find(5); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->getIdentityMap()); dump('$category1 === $category2', $category1 === $category2);<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     5 => App\\Entity\\Category {#1268 \u25bc       -id: 5       -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\"       -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}     }   ] ] \"$category1 === $category2\" true<\/code><\/pre>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/8af\/57a\/55f\/8af57a55fb6ce67032bd8d43d5da9488.png\" alt=\"\" title=\"\" width=\"982\" height=\"443\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8af\/57a\/55f\/8af57a55fb6ce67032bd8d43d5da9488.png\"\/><\/figure>\n<p><strong>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c (\u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 IdentityMap).<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 IdentityMap \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (ScheduledEntityUpdates)).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 EntityManager::flush() \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">$category = $em             ->getRepository(Category::class)             ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f']); dump('IdentityMap \u0434\u043e update', $em->getUnitOfWork()->getIdentityMap()); $category->setTitle('1234'); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 update', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityUpdates \u043f\u043e\u0441\u043b\u0435 update', $em->getUnitOfWork()->getScheduledEntityUpdates()); $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u0434\u043e update\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     92087 => App\\Entity\\Category {#1268 \u25bc       -id: 92087       -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\"       -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}     }   ] ] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 update\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     92087 => App\\Entity\\Category {#1268 \u25bc       -id: 92087       -title: \"1234\"       -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}     }   ] ] \"ScheduledEntityUpdates \u043f\u043e\u0441\u043b\u0435 update\" array:1 [\u25bc   1268 => App\\Entity\\Category {#1268 \u25bc     -id: 92087     -title: \"1234\"     -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}   } ]<\/code><\/pre>\n<p><strong>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c (\u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 IdentityMap).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 EntityManager::remove() \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445  (remove \u043e\u0442\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442 IdentityMap, \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f (ScheduledEntityDeletions)).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 EntityManager::flush() \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">$someCat = $em             ->getRepository(Category::class)             ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f']); dump('IdentityMap \u0434\u043e remove', $em->getUnitOfWork()->getIdentityMap()); $em->remove($someCat); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 remove', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityDeletions \u043f\u043e\u0441\u043b\u0435 remove', $em->getUnitOfWork()->getScheduledEntityDeletions()); $someCat->setTitle('123'); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityUpdates \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c', $em->getUnitOfWork()->getScheduledEntityUpdates()); $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u0434\u043e remove\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     92087 => App\\Entity\\Category {#1268 \u25b6}   ] ] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 remove\" array:1 [\u25bc   \"App\\Entity\\Category\" => [] ] \"ScheduledEntityDeletions \u043f\u043e\u0441\u043b\u0435 remove\" array:1 [\u25bc   1268 => App\\Entity\\Category {#1268 \u25bc     -id: 92087     -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\"     -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}   } ] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c\" array:1 [\u25bc   \"App\\Entity\\Category\" => [] ] \"ScheduledEntityUpdates \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c\" []<\/code><\/pre>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0432\u0438\u0434\u0435\u0442\u044c, \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u0441\u043b\u0435 remove() \u043d\u0435 \u043e\u0442\u043c\u0435\u043d\u044f\u044e\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442\u0432\u044f\u0437\u0430\u043d \u043e\u0442 IdentityMap .<\/p>\n<p><strong>EntityManager->clear()<\/strong><\/p>\n<p>\u0412\u043e \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0431\u043e\u0447\u0435\u0439 \u0441\u0435\u0441\u0441\u0438\u0438, EntityManager \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b. \u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e, \u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>EntityManager->clear() \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0447\u0438\u0441\u0442\u043a\u0438 EntityManager \u043e\u0442 \u0432\u0441\u0435\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0440\u0430\u043d\u0435\u0435. \u042d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0435\u0441\u043b\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0438\u043b\u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u0447\u0438\u0441\u0442\u044b\u043c EntityManager. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c, \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u044b\u043b\u0438 \u0432\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u0442\u0435\u0440\u044f\u043d\u044b, \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0431\u0443\u0434\u0443\u0442 \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u044b \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a \u043d\u0438\u043c.<\/p>\n<pre><code class=\"php\">\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430', memory_get_usage()); for ($i=0; $i &lt; 10000; $i++) {      $newCategory = new Category();     $newCategory->setTitle($i . 'title');     $em->persist($newCategory); } $em->flush(); \/\/$em->clear(); dump('UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439', $em->getUnitOfWork()->size()); \/\/ ... \u0418\u043d\u0430\u044f \u043b\u043e\u0433\u0438\u043a\u0430 $someCat = new Category(); $someCat->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2'); $em->persist($someCat); $em->flush(); dump('UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430', $em->getUnitOfWork()->size()); dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430', memory_get_usage());<\/code><\/pre>\n<pre><code class=\"sql\">\"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 25104248 \"UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\" 10000 \"UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 10001 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 99924992<\/code><\/pre>\n<p>\u0420\u0430\u0441\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u043c $em->clear() \u043d\u0430 9 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432 \u043a\u043e\u0434\u0435 \u0432\u044b\u0448\u0435<\/p>\n<pre><code class=\"sql\">\"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 25104248 \"UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\" 0 \"UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 1 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 89784832<\/code><\/pre>\n<p>\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0441\u043d\u0438\u0437\u0438\u043b\u043e\u0441\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u0438\u043c 10000 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 UnitOfWork.<\/p>\n<p>EntityManager \u0431\u043e\u043b\u044c\u0448\u0430\u044f \u0438 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0442\u0435\u043c\u0430, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u0430\u043b\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430, \u043d\u043e \u0432\u0430\u0436\u043d\u044b \u0434\u043b\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439. <\/p>\n<p>\u041f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435.<\/p>\n<h2>\u041f\u043e\u0438\u0441\u043a \u043f\u0440\u043e\u0431\u043b\u0435\u043c<\/h2>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \/upload. \u041d\u0430 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0436\u0443\u0440\u043d\u0430\u043b \u043f\u043e\u0441\u0435\u0449\u0435\u043d\u0438\u0439 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 XML \u0447\u0435\u0440\u0435\u0437 \u0444\u043e\u0440\u043c\u0443 \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435.<\/p>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0444\u0430\u0439\u043b (data.xml).<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430 data.xml<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0424\u0430\u0439\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 1247  \u043c\u0435\u0441\u0442, 797 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, 20 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439. \u0412\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430:<\/p>\n<pre><code class=\"xml\">&lt;item key=\"2\">   &lt;title>Trantow-Schuster&lt;\/title>   &lt;category>eaque&lt;\/category>   &lt;users>Keshawn Rosenbaum| Hillary Feil| Prof. Zena Kub PhD| &lt;\/users> &lt;\/item><\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/eb8\/2a8\/606\/eb82a860659883532b9c2b93549ef603.png\" width=\"997\" height=\"272\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/eb8\/2a8\/606\/eb82a860659883532b9c2b93549ef603.png\"\/><\/figure>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0435 \u043b\u0443\u0447\u0448\u0438\u0439, 20 \u0441\u0435\u043a\u0443\u043d\u0434 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u0431\u043e\u043b\u0435\u0435 13 \u0442\u044b\u0441\u044f\u0447 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0434. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430.<\/p>\n<p>\u042d\u0442\u043e \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 (uploadXmlForm), \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0438\u0439 \u0437\u0430 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \/upload \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u043e\u0440\u043c\u044b:<\/p>\n<pre><code class=\"php\">    #[Route('\/upload', name: 'app_index_uploadForm', methods: ['GET', 'POST'])]     public function uploadXmlForm(Request $request, IndexImportService $indexImportService): Response     {             $form = $this->createFormBuilder()         ->add('file', FileType::class)         ->add('submit', SubmitType::class, ['label' => 'Upload'])         ->getForm();             $form->handleRequest($request);         if ($form->isSubmitted() &amp;&amp; $form->isValid()) {             $file = $form->get('file')->getData();             \/\/ \u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0444\u0430\u0439\u043b\u0430             $indexImportService->importFromXml($file);              return $this->render('index\/uploadXML.html.twig', [                 'form' => $form->createView(),                 'message' => 'Upload completed'             ]);          }              return $this->render('index\/uploadXML.html.twig', [             'form' => $form->createView(),             'message' => ''         ]);              }<\/code><\/pre>\n<p>\u041e\u043f\u044f\u0442\u044c \u0432\u0441\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u0441\u0435\u0440\u0432\u0438\u0441\u0435 IndexImportService, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<p>\u042d\u0442\u043e \u043a\u043e\u0434 IndexImportService:<\/p>\n<pre><code class=\"php\">   public function importFromXml(mixed $file):void {         \/\/ Truncate \u0442\u0430\u0431\u043b\u0438\u0446 Category, User, Place \u0438 \u0438\u0445 \u0441\u0432\u044f\u0437\u0435\u0439         $this->clearTableService->clearAllIndexTable();         \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430         $xmlData = simplexml_load_file($file);         \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b         $categoriesFromFile = array_unique($xmlData->xpath('\/\/category'));         $usersFromFile = array_unique($xmlData->xpath('\/\/users'));         $placesFromFile = $this->fromXmlToArr($xmlData);         \/\/ \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445         $this->processCategory($categoriesFromFile);         $this->processUser($this->getUsersFromFile($usersFromFile));         $this->processPlace($placesFromFile);     }      private function processCategory(array $categories):void {          foreach($categories as $cat) {             \/\/ \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c DTO             $categoryDTO = new CategoryDTO($cat->__toString());             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO, \u0434\u0435\u043b\u0430\u0435\u043c persist             $category = new Category();             $category->setTitle($categoryDTO->title);             $this->em->persist($category);             \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441 \u0431\u0434             $this->em->flush();          }      }      private function processUser(array $users):void {          foreach($users as $user) {             \/\/ \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c DTO             $userDTO = new UserDTO($user,true);             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO, \u0434\u0435\u043b\u0430\u0435\u043c persist             $newUser = new User();             $newUser->setName($userDTO->name);             $newUser->setIsActive($userDTO->isActive);             $this->em->persist($newUser);             \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441 \u0431\u0434             $this->em->flush();          }      }      private function processPlace(array $array):void {         foreach ($array as $item) {             \/\/ \u041f\u043e\u0438\u0441\u043a \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u043e title             $categoryDTO = new CategoryDTO($item['category']);             $category = $this->em             ->getRepository(Category::class)             ->findOneBy(['title'=>$categoryDTO->title]);             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO             $placeDTO = new PlaceDTO($item['title']);             $place = new Place();             $place->setTitle($placeDTO->title);             $place->setCategory($category);             \/\/ \u041f\u043e\u0438\u0441\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439             $users = $this->getUsersFromItem($item['users']);             foreach ($users as $user) {                  $user = $this->em                 ->getRepository(User::class)                 ->findOneBy(['name'=>$user]);                  $place->addUser($user);             }             $this->em->persist($place);             \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441 \u0431\u0434             $this->em->flush();         }     } <\/code><\/pre>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u0431\u0440\u043e\u0441\u0430\u0435\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0437\u0430, \u044d\u0442\u043e \u0432\u044b\u0437\u043e\u0432 flush() \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u044d\u0442\u043e\u0433\u043e.<\/p>\n<h3>Bulk Inserts<\/h3>\n<p>\u0414\u043b\u044f \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c em, \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 flush() \u043d\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0430 \u0434\u043b\u044f \u0433\u0440\u0443\u043f\u043f\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. <\/p>\n<p>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 IndexImportService \u043f\u043e\u0434 \u043c\u0430\u0441\u0441\u043e\u0432\u0443\u044e \u0432\u0441\u0442\u0430\u0432\u043a\u0443 \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f UnitOfWork \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>IndexImportService \u0441 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\"> public function importFromXml(mixed $file):void {         \/\/ Truncate \u0442\u0430\u0431\u043b\u0438\u0446 Category, User, Place \u0438 \u0438\u0445 \u0441\u0432\u044f\u0437\u0435\u0439         $this->clearTableService->clearAllIndexTable();         \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430         $xmlData = simplexml_load_file($file);         \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b         $categoriesFromFile = array_unique($xmlData->xpath('\/\/category'));         $usersFromFile = array_unique($xmlData->xpath('\/\/users'));         $placesFromFile = $this->fromXmlToArr($xmlData);          \/\/ \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438', memory_get_usage());         $this->processCategory($categoriesFromFile);         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439', memory_get_usage());         dump('UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439', $this->em->getUnitOfWork()->size());         $this->processUser($this->getUsersFromFile($usersFromFile));         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439', memory_get_usage());         dump('UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439', $this->em->getUnitOfWork()->size());         $this->processPlace($placesFromFile);         dump('UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430', $this->em->getUnitOfWork()->size());         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430', memory_get_usage());      }      private function processCategory(array $categories):void {          foreach($categories as $cat) {             \/\/ \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c DTO             $categoryDTO = new CategoryDTO($cat->__toString());             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO, \u0434\u0435\u043b\u0430\u0435\u043c persist             $category = new Category();             $category->setTitle($categoryDTO->title);             $this->em->persist($category);         }            \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438            $this->em->flush();      }      private function processUser(array $users):void {          foreach($users as $user) {             \/\/ \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c DTO             $userDTO = new UserDTO($user,true);             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO, \u0434\u0435\u043b\u0430\u0435\u043c persist             $newUser = new User();             $newUser->setName($userDTO->name);             $newUser->setIsActive($userDTO->isActive);             $this->em->persist($newUser);         }         \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439         $this->em->flush();      }      private function processPlace(array $array):void {         foreach ($array as $item) {             \/\/ \u041f\u043e\u0438\u0441\u043a \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u043e title             $categoryDTO = new CategoryDTO($item['category']);             $category = $this->em             ->getRepository(Category::class)             ->findOneBy(['title'=>$categoryDTO->title]);             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO             $placeDTO = new PlaceDTO($item['title']);             $place = new Place();             $place->setTitle($placeDTO->title);             $place->setCategory($category);             \/\/ \u041f\u043e\u0438\u0441\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439             $users = $this->getUsersFromItem($item['users']);             foreach ($users as $user) {                  $user = $this->em                 ->getRepository(User::class)                 ->findOneBy(['name'=>$user]);                  $place->addUser($user);             }             $this->em->persist($place);         }         \/\/ \u0421\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u0432\u0441\u0435 \u043c\u0435\u0441\u0442\u0430         $this->em->flush();     }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u043d\u043e\u0432\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0444\u0430\u0439\u043b \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/06d\/099\/d9a\/06d099d9aaeac2c3fbc1ed3e86f7728a.png\" width=\"1032\" height=\"270\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/06d\/099\/d9a\/06d099d9aaeac2c3fbc1ed3e86f7728a.png\"\/><\/figure>\n<pre><code class=\"sql\">\"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438\" 31627920 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\" 33904120 \"UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\" 20 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\" 39620368 \"UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\" 817 \"UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 2064 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 67502952<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441 13  \u0434\u043e 9 \u0442\u044b\u0441\u044f\u0447 \u0438 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441 20 \u0434\u043e 3.4 \u0441\u0435\u043a.<\/p>\n<p>\u0422\u0435\u043a\u0443\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c\u044b\u0439 \u0444\u0430\u0439\u043b, \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0435\u0442 UnitOfWork \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c, \u0447\u0442\u043e \u043d\u0435\u0438\u0437\u0431\u0435\u0436\u043d\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u043e\u0448\u0438\u0431\u043a\u0435 \u043f\u043e \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043b\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u0432 \u043f\u0430\u043c\u044f\u0442\u0438 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c Batch processing (\u043f\u0430\u043a\u0435\u0442\u043d\u0430\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0430).<\/p>\n<h2>Batch Processing<\/h2>\n<p>\u0412 <a href=\"https:\/\/www.doctrine-project.org\/projects\/doctrine-orm\/en\/2.14\/reference\/batch-processing.html\" rel=\"noopener noreferrer nofollow\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u044b \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 SQLLogger). \u0415\u0441\u043b\u0438 \u043a\u0440\u0430\u0442\u043a\u043e, \u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0445\u043e\u0436 \u0441 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0435\u0439, \u043c\u044b \u0434\u0435\u043b\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u0447\u0430\u0441\u0442\u0438 \u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0434 (flush()) \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0447\u0430\u0441\u0442\u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 clear(), \u0447\u0442\u043e\u0431\u044b \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c Unit of work, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u043e\u0441\u0432\u043e\u0431\u043e\u0434\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c.<\/p>\n<p>\u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043a\u043e\u0434 IndexImportService \u043f\u043e\u0434 \u043f\u0430\u043a\u0435\u0442\u043d\u0443\u044e \u0432\u0441\u0442\u0430\u0432\u043a\u0443:<\/p>\n<details class=\"spoiler\">\n<summary>IndexImportService \u0441 \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u043e\u0439<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">public function importFromXml(mixed $file):void {         \/\/ Truncate \u0442\u0430\u0431\u043b\u0438\u0446 Category, User, Place \u0438 \u0438\u0445 \u0441\u0432\u044f\u0437\u0435\u0439         $this->clearTableService->clearAllIndexTable();         \/\/ \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430         $xmlData = simplexml_load_file($file);         \/\/ \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0432 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0433\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b         $categoriesFromFile = array_unique($xmlData->xpath('\/\/category'));         $usersFromFile = array_unique($xmlData->xpath('\/\/users'));         $placesFromFile = $this->fromXmlToArr($xmlData);          \/\/ \u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438', memory_get_usage());         $this->processCategory($categoriesFromFile);         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439', memory_get_usage());         dump('UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439', $this->em->getUnitOfWork()->size());         $this->processUser($this->getUsersFromFile($usersFromFile));         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439', memory_get_usage());         dump('UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439', $this->em->getUnitOfWork()->size());         $this->processPlace($placesFromFile);         dump('UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430', $this->em->getUnitOfWork()->size());         dump('\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430', memory_get_usage());      }      private function processCategory(array $categories):void {         \/\/ \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0437\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441         $count     = 1;         $batchSize = 250;         foreach($categories as $cat) {             \/\/ \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c DTO             $categoryDTO = new CategoryDTO($cat->__toString());             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO, \u0434\u0435\u043b\u0430\u0435\u043c persist             $category = new Category();             $category->setTitle($categoryDTO->title);             $this->em->persist($category);              if ($count % $batchSize === 0) {                 $this->em->flush();                 \/\/ \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c EntityManager \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438                 $this->em->clear();                 $count = 1;             } else {                 $count++;             }         }            $this->em->flush();            $this->em->clear();     }      private function processUser(array $users):void {         \/\/ \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0437\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441         $count     = 1;         $batchSize = 250;         foreach($users as $user) {             \/\/ \u0417\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c DTO             $userDTO = new UserDTO($user,true);             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO, \u0434\u0435\u043b\u0430\u0435\u043c persist             $newUser = new User();             $newUser->setName($userDTO->name);             $newUser->setIsActive($userDTO->isActive);             $this->em->persist($newUser);             if ($count % $batchSize === 0) {                 $this->em->flush();                 \/\/ \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c EntityManager \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438                 $this->em->clear();                 $count = 1;             } else {                 $count++;             }         }            $this->em->flush();            $this->em->clear();     }      private function processPlace(array $array):void {         \/\/ \u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0437\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441         $count     = 1;         $batchSize = 250;         foreach ($array as $item) {             \/\/ \u041f\u043e\u0438\u0441\u043a \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0439 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u043f\u043e title             $categoryDTO = new CategoryDTO($item['category']);             $category = $this->em             ->getRepository(Category::class)             ->findOneBy(['title'=>$categoryDTO->title]);             \/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 DTO             $placeDTO = new PlaceDTO($item['title']);             $place = new Place();             $place->setTitle($placeDTO->title);             $place->setCategory($category);             \/\/ \u041f\u043e\u0438\u0441\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439             $users = $this->getUsersFromItem($item['users']);             foreach ($users as $user) {                  $user = $this->em                 ->getRepository(User::class)                 ->findOneBy(['name'=>$user]);                  $place->addUser($user);             }             $this->em->persist($place);             if ($count % $batchSize === 0) {                 $this->em->flush();                 \/\/ \u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c EntityManager \u0434\u043b\u044f \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438                 $this->em->clear();                 $count = 1;             } else {                 $count++;             }         }            $this->em->flush();            $this->em->clear();     }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/0b2\/d9f\/b60\/0b2d9fb60a8943274a8f9fde42755756.png\" width=\"1032\" height=\"270\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/0b2\/d9f\/b60\/0b2d9fb60a8943274a8f9fde42755756.png\"\/><\/figure>\n<pre><code class=\"sql\">\"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438\" 31630568 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\" 33886008 \"UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439\" 0 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\" 38852552 \"UnitOfWork \u043f\u043e\u0441\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439\" 0 \"UnitOfWork \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 0 \"\u041f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043a\u0440\u0438\u043f\u0442\u0430\" 64735376<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u043b\u043e\u0441\u044c \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432, \u043d\u043e \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u0441\u0442\u0430\u0442\u044c\u0438, \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438  \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u043e\u0439 em, \u0438 \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0435 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0430\u0439\u043b, \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0435\u0433\u043e \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u043d\u0438\u043c\u0438. <\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0432 \u043a\u043e\u0434\u0435 simpleXml \u2014 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430 \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0433\u0440\u0443\u0437\u0438\u0442 \u0435\u0451 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c, \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0439 \u0438\u0437 xml \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043d\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u043d\u0435 \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u0441 \u0432\u044b\u0441\u043e\u043a\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439. <\/p>\n<p>\u041a\u043e\u043c\u0431\u0438\u043d\u0430\u0446\u0438\u044f ORM \u0438 UnitOfWork \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c \u0432\u044b\u0431\u043e\u0440\u043e\u043c \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043e\u0431\u044a\u0435\u043c\u043e\u0432 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0432\u0441\u0442\u0430\u0432\u043a\u0438, \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438\u043b\u0438 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u0442\u043e\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0421\u0423\u0411\u0414. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 SQL, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 processCategory():<\/p>\n<details class=\"spoiler\">\n<summary>SQL \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 processCategory():<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"sql\">doctrine.DEBUG: Beginning transaction [] [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92038,\"2\":\"enim\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92038,\"2\":\"enim\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92039,\"2\":\"delectus\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92039,\"2\":\"delectus\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92040,\"2\":\"eaque\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92040,\"2\":\"eaque\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92041,\"2\":\"est\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92041,\"2\":\"est\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92042,\"2\":\"tempore\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92042,\"2\":\"tempore\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92043,\"2\":\"quia\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92043,\"2\":\"quia\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92044,\"2\":\"quo\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92044,\"2\":\"quo\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92045,\"2\":\"sequi\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92045,\"2\":\"sequi\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92046,\"2\":\"vero\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92046,\"2\":\"vero\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92047,\"2\":\"adipisci\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92047,\"2\":\"adipisci\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92048,\"2\":\"quae\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92048,\"2\":\"quae\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92049,\"2\":\"rerum\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92049,\"2\":\"rerum\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92050,\"2\":\"fuga\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92050,\"2\":\"fuga\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92051,\"2\":\"consequatur\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92051,\"2\":\"consequatur\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92052,\"2\":\"dicta\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92052,\"2\":\"dicta\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92053,\"2\":\"unde\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92053,\"2\":\"unde\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92054,\"2\":\"dolor\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92054,\"2\":\"dolor\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92055,\"2\":\"provident\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92055,\"2\":\"provident\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92056,\"2\":\"possimus\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92056,\"2\":\"possimus\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Executing statement: INSERT INTO category (id, title) VALUES (?, ?) (parameters: array{\"1\":92057,\"2\":\"quidem\"}, types: array{\"1\":1,\"2\":2}) {\"sql\":\"INSERT INTO category (id, title) VALUES (?, ?)\",\"params\":{\"1\":92057,\"2\":\"quidem\"},\"types\":{\"1\":1,\"2\":2}} [] doctrine.DEBUG: Committing transaction [] []<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0414\u043b\u044f \u0432\u0441\u0442\u0430\u0432\u043a\u0438 20 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0439 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f 20 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 insert. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f $entityManager->getConnection()->insert(&#8216;table&#8217;, $data) \u0438\u043b\u0438 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 SQL  \u043c\u043e\u0436\u043d\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438 \u0437\u0430 1 \u0437\u0430\u043f\u0440\u043e\u0441 insert.<\/p>\n<h3>\u0412\u043c\u0435\u0441\u0442\u043e \u0438\u0442\u043e\u0433\u043e\u0432<\/h3>\n<p>\u041c\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b\u0438 Bulk inserts \u0438 Batch processing \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c Doctrine, \u043d\u0430\u043c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u0435\u043d\u0438\u0435 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041d\u043e \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043e\u0434\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445, \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 \u0432\u044b\u0441\u043e\u043a\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435\u043c\u044b: \u043f\u043e\u0442\u043e\u043a\u043e\u0432\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u0430, \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u044b \u0438 \u0438\u0442\u0435\u0440\u0430\u0442\u043e\u0440\u044b, \u0437\u0430\u0434\u0430\u0447\u0438 \u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043c\u0430\u0441\u0441\u043e\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0431\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432. \u0415\u0441\u043b\u0438 \u0431\u044b\u043b\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u043a\u043b\u0430\u0441\u0441\u044b. \u0412\u0441\u0435\u043c \u0434\u043e\u0431\u0440\u0430!<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/732470\/\"> https:\/\/habr.com\/ru\/articles\/732470\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u0445 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e! <\/p>\n<p>\u042d\u0442\u043e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439, \u0433\u0434\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043c\u043e\u0433\u0443\u0442 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c entity manager, unit of work, bulk inserts \u0438 batching processing \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u043e\u043c\u043d\u044e, \u0447\u0442\u043e \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043b \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0435 \u043e\u0448\u0438\u0431\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443 \u043d\u0430\u0439\u0442\u0438 \u0438 \u0438\u0441\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0438\u0445.<\/p>\n<p>\u0412<a href=\"https:\/\/habr.com\/ru\/articles\/729360\/\" rel=\"noopener noreferrer nofollow\"> \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 n+1, \u0432\u0438\u0434\u0430\u0445 \u043f\u0430\u0433\u0438\u043d\u0430\u0446\u0438\u0438 \u0438 \u0438\u043d\u0434\u0435\u043a\u0441\u0430\u0445. \u0422\u0430\u043c \u0436\u0435 \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u0438 \u0441\u0445\u0435\u043c\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/strong> &#8212; \u043f\u0440\u043e\u0435\u043a\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u0441 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0446\u0435\u043b\u044c\u044e \u0438 \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u0435\u0442 \u043d\u0430 \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0443, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u0436\u043d\u044b\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0438\u043b\u0438 \u0443\u043f\u0440\u043e\u0449\u0435\u043d\u044b, \u0432 \u043d\u0430\u0434\u0435\u0436\u0434\u0435, \u0447\u0442\u043e \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442\u0441\u044f \u0442\u0435\u043c\u043e\u0439 \u0438 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0444\u0435\u0441\u0441\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u043e\u0439.<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u043e Unit of Work \u0438 EntityManager<\/h2>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 ORM, \u0432\u0430\u0436\u043d\u043e \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u0432\u0441\u0435\u043c\u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438 \u043d\u0430\u0434 \u044d\u0442\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438, \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c, \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c \u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 Doctrine \u044d\u0442\u0438\u043c \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f EntityManager.<\/p>\n<p>EntityManager (em) &#8212; \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 ORM, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u043c \u0446\u0438\u043a\u043b\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0438\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. EntityManager \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a Doctrine \u0438 \u043a \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0443 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0442\u0435, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u0442\u043e\u043b\u043a\u043d\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u0435\u0435, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: Unit of Work, Identity Map \u0438 Transactional write-behind.<\/p>\n<p><a href=\"https:\/\/www.martinfowler.com\/eaaCatalog\/unitOfWork.html\" rel=\"noopener noreferrer nofollow\">Unit of Work<\/a> (uow) &#8212; \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u0440\u043e\u0435\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 ORM \u0434\u043b\u044f \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0438 \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0446\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0435\u0434\u0438\u043d\u0438\u0446\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u044f), \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044f \u0446\u0435\u043b\u043e\u0441\u0442\u043d\u043e\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0438 \u043f\u0440\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0438. \u041a\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043d\u0430\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c (\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0435, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0438 \u0434\u0440.), \u043e\u043d\u0438 \u043f\u043e\u043c\u0435\u0447\u0430\u044e\u0442\u0441\u044f <a href=\"https:\/\/www.doctrine-project.org\/projects\/doctrine-orm\/en\/2.14\/reference\/events.html#onflush\" rel=\"noopener noreferrer nofollow\">(NEW,MANAGED,DETACHED, REMOVED)<\/a> \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u043b\u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 Unit of Work. \u0417\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 flush() \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0441 \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445. <\/p>\n<p>IdentityMap \u0445\u0440\u0430\u043d\u0438\u0442 \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 ORM, \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u0435\u0434\u0438\u043d\u0438\u0446\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0430 \u0440\u043e\u0432\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u043b\u0438\u043a\u0442\u043e\u0432 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438, \u043a\u043e\u0433\u0434\u0430 \u0434\u0432\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u0445 \u043e\u0434\u0438\u043d \u0438 \u0442\u043e\u0442 \u0436\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0435, \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u044b \u043f\u043e-\u0440\u0430\u0437\u043d\u043e\u043c\u0443.<\/p>\n<p>Transactional write-behind &#8212; \u0441\u0443\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0438 \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438, \u043d\u0435 \u0441\u0440\u0430\u0437\u0443 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043e\u0442\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 (\u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 flush()).<\/p>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0430\u0441\u0442\u044b\u0435 \u0441\u043b\u0443\u0447\u0430\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f em.<\/p>\n<p><strong>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430<\/strong><\/p>\n<p>\u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 EntityManager \u0438 UnitOfWork, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0431\u0443\u0434\u0435\u0442 &#171;New&#187; . \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u0437\u043e\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430 persist(), Doctrine \u043f\u043e\u043c\u0435\u0447\u0430\u0435\u0442 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 &#171;Managed&#187;, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u0432\u0441\u0442\u0430\u0432\u043a\u0438 (ScheduledEntityInsertions) \u0438 \u0432 IdentityMap. \u041f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 flush() \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430 \u043e\u0436\u0438\u0434\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u044b \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445:     <\/p>\n<pre><code class=\"php\">\/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044c\u0435\u043a\u0442 $category = new Category(); $category->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 1'); \/\/ \u042d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043d\u043e\u0432\u043e\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e\u0439 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u043e\u0441\u0442\u0438 \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d \u0441 EntityManager \u0438 UnitOfWork  dump('IdentityMap \u0434\u043e persist', $em->getUnitOfWork()->getIdentityMap()); \/\/ \u041e\u0431\u044c\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 UnitOfWork (IdentityMap \u0438 ScheduledEntityInsertions) $em->persist($category); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 persist', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 persist', $em->getUnitOfWork()->getScheduledEntityInsertions()); \/\/ \u041e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0431\u0434, \u0430\u043a\u0442\u0443\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 UnitOfWork, \u0443\u0434\u0430\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 ScheduledEntityInsertions $em->flush(); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 flush', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 flush', $em->getUnitOfWork()->getScheduledEntityInsertions());<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u0434\u043e persist\": [] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 persist\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25b6] ] \"ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 persist\" array:1 [\u25bc   1325 => App\\Entity\\Category {#1325 \u25b6} ] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 flush\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25b6] ] \"ScheduledEntityInsertions \u043f\u043e\u0441\u043b\u0435 flush\" [] \"SQL \u0437\u0430\u043f\u0440\u043e\u0441\" \"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2510   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 1\" ] \"COMMIT\"<\/code><\/pre>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0438\u0436\u0435 \u044d\u0442\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 Transactional write-behind. \u041c\u044b \u043d\u0430\u043a\u043e\u043f\u0438\u043b\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u0432\u0443\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0438 \u0437\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u0438\u0445 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438.<\/p>\n<pre><code class=\"php\">\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0438  $cat2 = new Category(); $cat2->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2'); $cat3 = new Category(); $cat3->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3'); \/\/ \u041d\u0430\u043a\u0430\u043f\u043b\u0438\u0432\u0430\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f $em->persist($cat2); $em->persist($cat3); \/\/ \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u043c \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0437\u0430\u043a\u0446\u0438\u0438 $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"SQL \u0437\u0430\u043f\u0440\u043e\u0441\" \"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2512   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ] INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2513   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3\" ] \"COMMIT\" <\/code><\/pre>\n<p>\u041d\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0431\u0434 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u0438\u043b\u0438 \u0433\u0440\u0443\u043f\u043f\u044b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432) \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438:<\/p>\n<pre><code class=\"php\">$cat2 = new Category(); $cat2->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2'); $cat3 = new Category(); $cat3->setTitle('\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3'); $em->persist($cat2); $em->flush(); $em->persist($cat3); $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2521   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ] \"COMMIT\" \"START TRANSACTION\" INSERT INTO category (id, title) VALUES (?, ?) Parameters: [\u25bc   2522   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 3\" ] \"COMMIT\"<\/code><\/pre>\n<p><strong>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/strong><\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, Doctrine \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 IdentityMap, \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 &#171;Managed&#187; \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442 \u0432\u0441\u0435 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0438\u0437 \u0431\u0434 . \u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u044d\u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0435\u0449\u0435 \u0440\u0430\u0437, Doctrine \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442, \u0430 \u0432\u0435\u0440\u043d\u0435\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0438\u0437 IdentityMap. <\/p>\n<pre><code class=\"php\">dump('\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u0434\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->size()); \/\/ \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c $category1 = $em->getRepository(Category::class) ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2']); \/\/ \u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c $category2 = $em->getRepository(Category::class) ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2']); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->getIdentityMap()); dump('\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->size()); dump('$category1 === $category2', $category1 === $category2); <\/code><\/pre>\n<pre><code class=\"sql\">\"\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u0434\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" 0 \"IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     5 => App\\Entity\\Category {#1286 \u25bc       -id: 5       -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\"       -places: Doctrine\\ORM\\PersistentCollection {#1059 \u25b6}     }   ] ] \"\u0420\u0430\u0437\u043c\u0435\u0440 Unit of Work \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" 1 \"$category1 === $category2\" true \"SQL \u0437\u0430\u043f\u0440\u043e\u0441\" SELECT t0.id AS id_1, t0.title AS title_2 FROM category t0 WHERE t0.title = ? LIMIT 1 Parameters: [\u25bc   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ] View formatted query    View runnable query    Explain query 20.87 ms SELECT t0.id AS id_1, t0.title AS title_2 FROM category t0 WHERE t0.title = ? LIMIT 1 Parameters: [\u25bc   \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\" ]<\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u0436\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 IdentityMap, \u0442\u043e \u043f\u0440\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0432\u044b\u0437\u043e\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 find() Doctrine \u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 findBy, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445), \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u043f\u043e\u0438\u0441\u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0432 IdentityMap.<\/p>\n<pre><code class=\"php\">\/\/ \u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c $category1 = $em->getRepository(Category::class) ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2']); \/\/ \u041f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u043e\u043c find $category2 = $em->getRepository(Category::class) ->find(5); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432', $em->getUnitOfWork()->getIdentityMap()); dump('$category1 === $category2', $category1 === $category2);<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     5 => App\\Entity\\Category {#1268 \u25bc       -id: 5       -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f 2\"       -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}     }   ] ] \"$category1 === $category2\" true<\/code><\/pre>\n<p>\u0413\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435<\/strong><\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c (\u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 IdentityMap).<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 (\u041f\u043e\u0441\u043b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 IdentityMap \u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u0432 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (ScheduledEntityUpdates)).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 EntityManager::flush() \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">$category = $em             ->getRepository(Category::class)             ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f']); dump('IdentityMap \u0434\u043e update', $em->getUnitOfWork()->getIdentityMap()); $category->setTitle('1234'); dump('IdentityMap \u043f\u043e\u0441\u043b\u0435 update', $em->getUnitOfWork()->getIdentityMap()); dump('ScheduledEntityUpdates \u043f\u043e\u0441\u043b\u0435 update', $em->getUnitOfWork()->getScheduledEntityUpdates()); $em->flush();<\/code><\/pre>\n<pre><code class=\"sql\">\"IdentityMap \u0434\u043e update\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     92087 => App\\Entity\\Category {#1268 \u25bc       -id: 92087       -title: \"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f\"       -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}     }   ] ] \"IdentityMap \u043f\u043e\u0441\u043b\u0435 update\" array:1 [\u25bc   \"App\\Entity\\Category\" => array:1 [\u25bc     92087 => App\\Entity\\Category {#1268 \u25bc       -id: 92087       -title: \"1234\"       -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}     }   ] ] \"ScheduledEntityUpdates \u043f\u043e\u0441\u043b\u0435 update\" array:1 [\u25bc   1268 => App\\Entity\\Category {#1268 \u25bc     -id: 92087     -title: \"1234\"     -places: Doctrine\\ORM\\PersistentCollection {#1061 \u25b6}   } ]<\/code><\/pre>\n<p><strong>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435<\/strong><\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0443\u0436\u043d\u043e \u0443\u0434\u0430\u043b\u0438\u0442\u044c (\u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0432 IdentityMap).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 EntityManager::remove() \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u0437 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445  (remove \u043e\u0442\u0432\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0442 IdentityMap, \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0437\u0430\u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f (ScheduledEntityDeletions)).<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 EntityManager::flush() \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<\/li>\n<\/ol>\n<pre><code class=\"php\">$someCat = $em             ->getRepository(Category::class)             ->findOneBy(['title'=>'\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u044f']); dump('IdentityMap \u0434\u043e remove', $em->getUnitOfWork()->getIdentityMap());<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-398452","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/398452","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=398452"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/398452\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=398452"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=398452"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=398452"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}