addiks/doctrine2_tweaks 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

addiks/doctrine2_tweaks

Composer 安装命令:

composer require addiks/doctrine2_tweaks

包简介

Some component-replacements with tweaks and modified behaviour for the doctrine2 project.

README 文档

README

Build Status

This repository represents a collection of alternative components with tweaks and/or changed behaviour for the doctrine2-project.

UnitOfWork Save-State

Addiks\DoctrineTweaks\UnitOfWork\UnitOfWorkSaveState

This represents a save-state of a doctrine unit-of-work instance. Using this, you can always revert the state of a unit-of-work instance back to a previous state.

This can be useful for bulk-operations: Create a save-state at the beginning of the bulk-process and then restore it after every flush. That way the unit-of-work will never contain objects that were already flushed, saving memory and (execution-)time.

This differs from a simple entity-manager clear call because it leaves all objects in the unit-of-work that were in it when the save state was created. Keeping these objects in it can (and often will) help with keeping the state of the unit-of-work consistent with the rest of the application.

Remember to also call "gc_collect_cycles()" when restoring to actually free the memory.

Example:

<?php

use Addiks\DoctrineTweaks\UnitOfWork\UnitOfWorkSaveState;

$saveState = new UnitOfWorkSaveState($entityManager->getUnitOfWork());

foreach ($thingsToImport as $counter => $thing) {

    $importer->import($thing); # Import a thing, add it to a collection or something

    if ($counter % 100 === 0) {
        $entityManager->flush(); # Send new entities to database
        $saveState->restore(); # Remove imported entities from unit-of-work
        gc_collect_cycles(); # Clean up memory
    }
}

Transactional Entity-Manager:

Addiks\DoctrineTweaks\TransactionalEntityManager (Alternative for Doctrine\ORM\EntityManager)

Manages entities for persistence via ORM.

This entity-manager poses an alternative to doctrine's own entity-manager. In contrast to doctrine's entity-manager, this entity-manager never closes. Instead, on rollback it rolls the managed part of all managed entities back to the point of when the transaction was created.

It does this by managing not only one UnitOfWork, but a stack of UnitOfWork-instances. There is one UnitOfWork per open transaction plus the root-UnitOfWork. Each UnitOfWork in this stack contains the state of managed entities from the time when the next transaction started. The top UnitOfWork on the stack is always the one currently used. When a transaction begins, the topmost UnitOfWork is cloned and the clone put on top of the stack becoming the new current UnitOfWork.

When a transaction get's committed, the secont-topmost UnitOfWork get's removed from the stack, replaced by the current and topmost UnitOfWork. There is also an alternative method to commit called "commitAndDetachNewEntities" that also detaches all entities that were not known at the beginning of the transaction, which may be what you want to do for every iteration in batch-processing in order to prevent having an enourmous amount of entities managed.

When a transaction get's rolled back, the topmost UnitOfWork get's discarded and it's previous UnitOfWork (which still contains the state of the entities of when the transaction begun becomes the new topmost and current one.

There is also an alternative method for rolling back a transaction called "rollbackEntities" that rolls back the managed part of the state of all managed entities using the UnitOfWork that still contains the state of the managed entities when the transaction begun (resulting in an expensive rollback!).

The process described in the paragraph above allows for a meaningful workflow using transactions. If a process fails and causes a rollback, not only the state in the database get's rolled back, but also the state of all managed entities. This allows for the executed and failed process to be re-tried again or to continue with the next process using the same entity-manager. This can be done because the state of the runtime is known, it is the same as at the beginning of the transaction. This follows the meaning of a "rollback" => The return from a faulty state into a well- known state. If correctly used, this entity-manager could save some developers that care deeply about transactions a big headache.

Please note that this component is currently only roughly tested and should be considered more like a proof-of-concept. If you actually do make the decision to use this in production environment, please test everything beforehand and look for any impact on performance. Please provide feedback if you actually do use this anywhere or even better, fork and improve it.

addiks/doctrine2_tweaks 适用场景与选型建议

addiks/doctrine2_tweaks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.91k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「php」 「sql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 addiks/doctrine2_tweaks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 addiks/doctrine2_tweaks 我们能提供哪些服务?
定制开发 / 二次开发

基于 addiks/doctrine2_tweaks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.91k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2020-02-11