代码之家  ›  专栏  ›  技术社区  ›  Toto

存储用户搜索电子邮件警报的最佳策略是什么?

  •  3
  • Toto  · 技术社区  · 14 年前

    用户可以进行高级搜索(它们是许多可能的参数):

    /search/?query=toto&topic=12&minimumPrice=0&maximumPrice=1000

    我想存储搜索参数(在 /search/? )电子邮件提醒。

    我有两种可能性:

    1. 存储原始请求( query=toto&topicId=12&minimumPrice=0&maximumPrice=1000 )在具有类似ID、参数等结构的表中。
    2. 将请求存储在结构化的表ID、查询、topicid、minimumPrice、maximumPrice等中。

    Each solution has its pros and cons. Of course the solution 2 is the cleaner, but is it really worth the (over)effort?

    If you already have implemented such a solution and have experienced the maintenance of it, what is the best solution?

    更好的解决方案应该是每个维度的最佳解决方案:

    1. 刚度
    2. 易碎性
    3. 粘度
    4. 性能
    3 回复  |  直到 14 年前
        1
  •  1
  •   Java Drinker    14 年前

    Daniel's solution is likely to be the cleanest solution, but I get your point about performance. I'm not very familiar with PHP, but there should be some db abstraction library that takes care relations and multiple inserts so that you get the best performance, right? I only mention it because there may not be a real performance issue. DO you have load tests that point to an issue perhaps?

    Anyway, if it is between your original 2 solutions, I would have to select the first. Having a table with column names (like your solution #2) is just asking for trouble. If you add new params, you have to modify the table columns. And there is the ever present issue of " 我们用什么来表示未选中vs左空?

    所以我不同意解决方案2更干净。

        2
  •  1
  •   Daniel Egeberg    14 年前

    您可以有一个由三列组成的表: search_id , key , value

    如果你愿意,你也可以 钥匙 be a foreign key to another table containing valid search terms to ensure integrity. Whether you want to do that depends on your specific needs though.

        3
  •  1
  •   gblazex    14 年前

    Well that's completely dependent on what you want to do with the data. For the PHP part, you need to process it anyway, either on insertion or selection time.

    For really large number of parameters you may save some time with the 1st on the database management/maintenance, since you don't need to change anything about your database scheme.

    Daniel's answer is a generic solution, but if you consider performance an issue, you may end up doing too many inserts on the database side for a single search (one for each parameter). Too many inserts is a common source of performance problems.

    你知道你的资源。