Silverstripe DataObject太大,无法使用MySQL / InnoDB保存

时间:2019-01-09 13:30:01

标签: php mysql silverstripe

有关使用PHP7.1,Silverstripe 3.6.0和MySQL的Web应用程序的问题。该应用程序托管在PaaS提供商上。因此,我无法直接访问数据库,也无法调整InnoDB,就像错误消息提示一样。

我有一个带有许多字段的自定义 DataObject 。尝试保存时返回奇怪的错误:

  

无法运行查询: [...此处有大更新查询...] 行大小太大(> 8126)。将某些列更改为TEXT或BLOB或使用ROW_FORMAT = DYNAMIC或ROW_FORMAT = COMPRESSED可能会有所帮助。在当前行格式中,内联存储了768个字节的BLOB前缀。

在这里您找到我班的简称:

class APIPersonResource extends DataObject {
  private static $db = array(
    'ResourceID' => 'Int',
    'Firstname' => 'Varchar(255)',
    'Lastname' => 'Varchar(255)',
    'Salutation' => 'Varchar(255)',
    'Email' => 'Varchar(255)',
    'HomepageLink' => 'Text',
    'PhoneNo' => 'Varchar(255)',
    'Info' => 'HTMLText',
    'IsResponsible' => 'Boolean',
    'ResponsibleDescription' => 'Varchar(255)',
    'ShortBio' => 'HTMLText',
    'RoomNo' => 'Varchar',
    'IsActive' => 'Boolean',
    'IsAcademic' => 'Boolean',
    'HasImage' => 'Boolean',
    'HasLinksSection' => 'Boolean',
    'HasCv' => 'Boolean',
    'HasPublications' => 'Boolean',
    'HasOfficeHours' => 'Boolean',
    'AreaOfFocus' => 'Varchar(64)',
    'OleLink' => 'Text',
    'ReserveCollectionLink' => 'Text',
    'ResearchAreas' => 'HTMLText',
    'APIDepartmentResourceID' => 'Int',
    'APIAddressResourceID' => 'Int',
    'APIDegreeResourceID' => 'Int'
  );
}

ShortBioAreaOfFocusResearchAreasInfo都是非常长的用户输入字段。奇怪的是,这些字段的类型为HTMLText,而在数据库表中,列的类型为mediumtext

MariaDB [leonixyz]> describe APIPersonResource;
+------------------------------+---------------------------------------------------+------+-----+-------------------+----------------+
| Field                        | Type                                              | Null | Key | Default           | Extra          |
+------------------------------+---------------------------------------------------+------+-----+-------------------+----------------+
| ID                           | int(11)                                           | NO   | PRI | NULL              | auto_increment |
| ClassName                    | enum('APIPersonResource','APIPhdStudentResource') | YES  | MUL | APIPersonResource |                |
| LastEdited                   | datetime                                          | YES  |     | NULL              |                |
| Created                      | datetime                                          | YES  |     | NULL              |                |
| Salutation_en_US             | varchar(255)                                      | YES  |     | NULL              |                |
| Salutation_de_DE             | varchar(255)                                      | YES  |     | NULL              |                |
| Salutation_it_IT             | varchar(255)                                      | YES  |     | NULL              |                |
| ResponsibleDescription_en_US | varchar(255)                                      | YES  |     | NULL              |                |
| ResponsibleDescription_de_DE | varchar(255)                                      | YES  |     | NULL              |                |
| ResponsibleDescription_it_IT | varchar(255)                                      | YES  |     | NULL              |                |
| ShortBio_en_US               | mediumtext                                        | YES  |     | NULL              |                |
| ShortBio_de_DE               | mediumtext                                        | YES  |     | NULL              |                |
| ShortBio_it_IT               | mediumtext                                        | YES  |     | NULL              |                |
| ResourceID                   | int(11)                                           | NO   |     | 0                 |                |
| Firstname                    | varchar(255)                                      | YES  |     | NULL              |                |
| Lastname                     | varchar(255)                                      | YES  |     | NULL              |                |
| Salutation                   | varchar(255)                                      | YES  |     | NULL              |                |
| Email                        | varchar(255)                                      | YES  |     | NULL              |                |
| PhoneNo                      | varchar(255)                                      | YES  |     | NULL              |                |
| IsResponsible                | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| ResponsibleDescription       | varchar(255)                                      | YES  |     | NULL              |                |
| ShortBio                     | mediumtext                                        | YES  |     | NULL              |                |
| IsActive                     | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| HasActiveContract            | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| APIDepartmentResourceID      | int(11)                                           | NO   |     | 0                 |                |
| RoomNo                       | varchar(50)                                       | YES  |     | NULL              |                |
| HasImage                     | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| HasCv                        | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| HasPublications              | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| APIAddressResourceID         | int(11)                                           | NO   |     | 0                 |                |
| AreaOfFocus_en_US            | varchar(64)                                       | YES  |     | NULL              |                |
| AreaOfFocus_de_DE            | varchar(64)                                       | YES  |     | NULL              |                |
| AreaOfFocus_it_IT            | varchar(64)                                       | YES  |     | NULL              |                |
| AreaOfFocus                  | varchar(64)                                       | YES  |     | NULL              |                |
| HomepageLink                 | mediumtext                                        | YES  |     | NULL              |                |
| Info_en_US                   | mediumtext                                        | YES  |     | NULL              |                |
| Info_de_DE                   | mediumtext                                        | YES  |     | NULL              |                |
| Info_it_IT                   | mediumtext                                        | YES  |     | NULL              |                |
| ResearchAreas_en_US          | mediumtext                                        | YES  |     | NULL              |                |
| ResearchAreas_de_DE          | mediumtext                                        | YES  |     | NULL              |                |
| ResearchAreas_it_IT          | mediumtext                                        | YES  |     | NULL              |                |
| Info                         | mediumtext                                        | YES  |     | NULL              |                |
| HasLinksSection              | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| HasOfficeHours               | tinyint(1) unsigned                               | NO   |     | 0                 |                |
| OleLink                      | mediumtext                                        | YES  |     | NULL              |                |
| ReserveCollectionLink        | mediumtext                                        | YES  |     | NULL              |                |
| ResearchAreas                | mediumtext                                        | YES  |     | NULL              |                |
| APIDegreeResourceID          | int(11)                                           | NO   |     | 0                 |                |
| IsAcademic                   | tinyint(1) unsigned                               | NO   |     | 0                 |                |
+------------------------------+---------------------------------------------------+------+-----+-------------------+----------------+

有没有一种方法可以解决我的问题而不将我的对象分成几部分?

预先感谢

1 个答案:

答案 0 :(得分:0)

您应该重构模型(例如,对# in some for loop or complex code node = Node("Example", name="Test",something="else") node.__primarykey__ = "name" <code merging or otherwise creating the node> # later on in the loop you might have done something like this cause the field was null node = Node("Example", something="new") node.__primarykey__ = "something" has_one使用1:1关系),或将RowFormat设置为压缩。可以使用以下代码针对每个DataObject进行此操作(来自SS3,但也应适用于SS4):

belongs_to