geonative / garbage-collector
Doctrine 实体垃圾回收器
0.2
2022-11-07 14:08 UTC
Requires
- php: >=8.0
- doctrine/doctrine-bundle: ^2.5
- doctrine/orm: ^2.10
- symfony/console: ^5.4|^6.0
- symfony/http-kernel: ^5.4|^6.0
- symfony/uid: ^5.4|^6.0
Requires (Dev)
- pestphp/pest: ^1.21
- symfony/yaml: ^5.4|^6.0
README
本包是一个 Symfony Bundle,提供了一项“垃圾回收器”命令,用于删除您认为过时的 Doctrine 实体。
安装
需要 PHP 8.0 或更高版本。
composer require geonative/garbage-collector
配置
-
将扩展包添加到您的
config/bundles.php
文件中(可能通过 Symfony Flex 自动完成)。 -
更新配置
# config/packages/doctrine.yaml doctrine: orm: mappings: GarbageCollectorBundle: ~
# config/services.yaml services: _instanceof: GeoNative\GarbageCollector\PrunableRepositoryInterface: tags: [!php/const GeoNative\GarbageCollector\Services\GarbageCollector::PRUNABLE_REPOSITORY]
- 更新数据库模式
php bin/console doctrine:schema:update --dump-sql --force
- 在您的存储库上实现
GeoNative\GarbageCollector\PrunableRepositoryInterface
getGarbageCollectorCheckInterval()
应返回检查之间的最小间隔,以避免影响数据库性能pruneStaleEntities()
应实际执行删除操作并返回已删除的实体数量。
如果您的实体应该针对 DateTime 列进行修剪,您可以使用 GeoNative\GarbageCollector\PruneStaleEntitiesTrait
来更快地开始。
使用
一次性
php bin/console gc:entities:prune
您可以将此存储在 crontab 中,以定期清理实体。
守护进程化
此命令也可以在循环中运行,并通过 supervisord 或 systemctl 守护进程化。
需要 react/event-loop
包。
php bin/console gc:entities:prune --loop=5
垃圾回收器每 5 秒遍历一次。
锁
如果您的应用程序在多个主机上运行,您可能希望 防止多个垃圾回收器实例同时运行。要这样做,只需添加一个 --lock
选项
php bin/console gc:entities:prune --lock
测试
vendor/bin/pest
许可
MIT。