dougan1205 2019-08-19 09:12
浏览 63

在网站的每个页面上都加载了非常大的php类。 需要重构建议

I've inherited a project that is using one file DBOperations for all interactions with out database. It's a huge mess of static function calls for read/writes. It's about 24,000 lines and maybe 1000 functions.

This file is then loaded using require_once in most pages. Just by including the file it adds about 300ms of load time. I need to sort this out and I'm looking for advice on how to approach it.

We don't have the resources to re-write everything so I want to re-organise everything.

I currently plan on splitting my big DBOperations file out into many smaller ones. Each database table will have it's own DBOps file e.g. my 'users' table will have a corresponding UsersDBOps.php file that will extend a class that will have some generic CRUD functions. I'll move all functions for the users table in DBOperations into UserDBOps. To prevent breaking any code I'll replace the code in DBOperations with a call to the function in UserDBOps. Finally I'll introduce autoloading.

So in summary my current plan is:

  1. Split DBOperations into DBOps files for each database table.
  2. Move all functions for a table to it's DBOps file. Update DBOperations functions to point to the new DBOps functions (prevent breaking my existing code)
  3. Slowly refactor all calls to DBOperations to the new DBOps files. Eventually I'll be able to get rid of DBOperations altogether.
  4. Introduce autoloading.

Would you make any changes to my plan?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?