简体   繁体   English

Yii2,使用 MYSQL 表或 a.php 文件

[英]Yii2, using a MYSQL table or a .php file

I have millions of texts to save in the database and to show through an application that I am developing with Yii2.我有数百万条文本要保存在数据库中,并通过我正在使用 Yii2 开发的应用程序显示。 A single text can vary from 30 to 500 words, but they are all similar to each other and respect a track where only a few words or values change.单个文本可以从 30 到 500 个字不等,但它们都彼此相似,并且尊重只有几个字或值发生变化的轨道。 To make you understand a text can be为了让你理解一个文本可以是

A) Goofy goes shopping on Wednesday at 2.30pm A) Goofy goes shopping on Wednesday at 2.30pm

or或者

B) Pluto goes shopping on Thursday at 4pm B) Pluto goes shopping on Thursday at 4pm

Instead of saving completely all the texts and words I intend to parameterize them, so I could create a track list我打算参数化它们,而不是完全保存所有文本和单词,所以我可以创建一个曲目列表

T1 {name} goes shopping on {day} at {hour} T1 {name} goes shopping on {day} at {hour}

T2 blah blah {param}... T2 blah blah {param}...

etc... ETC...

I guess I have 25-50 tracks.我想我有 25-50 首曲目。

By doing so, it is not longer necessary to save all the texts and words, so A) becomes a record with track T1 where {name} = Goofy, {day} = Wednesday and {hour} = 2.30pm.通过这样做,不再需要保存所有文本和单词,因此 A) 成为轨道 T1 的记录,其中 {name} = Goofy,{day} = Wednesday 和 {hour} = 2.30pm。

I intend to have a parameters table with this structure我打算有一个具有这种结构的参数表

text_id
parameter
value

There will be no text search in the application.应用程序中不会有文本搜索。 The only things that can be searched and filtered are parameters.唯一可以搜索和过滤的是参数。

To get the best performance, I should save all the tracks in a table or have them all stored in a.php file in an array of key => value and load it during the execution of the application to show each time the texts (of which I know only parameters saved in the db)?为了获得最佳性能,我应该将所有轨道保存在一个表中,或者将它们全部存储在一个key => value数组中的 a.php 文件中,并在应用程序执行期间加载它以显示每次文本(我只知道保存在数据库中的参数)?

Remembering how Yii handles messages translations through.php files containing arrays, I would like to do the same, but I ask you for confirmation.记住 Yii 如何通过.php 文件处理包含 arrays 的消息翻译,我也想做同样的事情,但我请你确认。 If so, what would be the optimal management?如果是这样,最佳管理方式是什么? Insert this array inside the.php model?将这个数组插入到.php model 里面? Or create another.php file to load in the necessary contexts?或者创建另一个.php 文件以在必要的上下文中加载? And where to insert it?以及在哪里插入? In the vendor folder?在供应商文件夹中?

Thanks谢谢

I'm not sure that you're asking the correct question (about relative performance).我不确定你问的是正确的问题(关于相对性能)。 I do like your thinking about how to store the data, because it reminds me of how I designed the storage of answers to questionnaires for one of the first online insurance underwriting engines.我确实喜欢您对如何存储数据的思考,因为它让我想起了我是如何为第一个在线保险承保引擎之一设计调查问卷答案的存储的。

I would strongly suggest, given that the majority of your data is going to go into the parameters table, and therefore the overhead of storing the tracks data is minimal, that you store the tracks data in the db too.我强烈建议,鉴于您的大部分数据都将 go 放入参数表中,因此存储曲目数据的开销很小,因此您也将曲目数据存储在数据库中。 This will allow you to perform joins directly in the db when necessary - and you will inevitably find reasons to do that.这将允许您在必要时直接在数据库中执行连接 - 您不可避免地找到这样做的理由。 You can then experiment yourself with reading them once into an array or object, on occasions when you would otherwise have to consult the tracks table multiple times in a single action/function.然后,您可以尝试将它们一次读入数组或 object,否则您必须在单个操作/函数中多次查阅轨道表。

Your parameters table will need a primary key, or your app will not scale, and if things are going to get really big, and if all of your values, as well as the parameters, are known, then you might also want to consider a further level of abstraction, where your parameters table stores numerical references to the parameters and values, ie it has four columns: unique_id, text_id, parameter_id, value_id, and the parameter_id and value_id are unique values from separate tables.您的参数表将需要一个主键,否则您的应用程序将无法扩展,并且如果事情变得非常大,并且如果您的所有值以及参数都是已知的,那么您可能还需要考虑更进一步的抽象,您的参数表存储对参数和值的数字引用,即它有四列:unique_id、text_id、parameter_id、value_id,并且 parameter_id 和 value_id 是来自不同表的唯一值。 This will give you a huge performance improvement, through optimised indexing.通过优化索引,这将为您带来巨大的性能提升。 Even if some of the values are free text, you could, as I did, cope with this with an additional column (but requiring extra code).即使某些值是自由文本,您也可以像我一样,通过额外的列(但需要额外的代码)来解决这个问题。

As I say, the above is all from real-world experience of designing a system that went from nothing to 1 million quotes per day in a couple of years, with each of those quotes requiring retention of 50+ parameter/value pairs similar to yours.正如我所说,以上内容均来自设计系统的实际经验,该系统在几年内从无到有达到每天 100 万个报价,其中每个报价都需要保留 50 多个与您相似的参数/值对.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM