dongnao2582 2017-02-08 05:27
浏览 55

存储要在数据库中执行的操作,还是从代码中决定?

I've got a website in which I want to send some followup emails to customers a certain number of days after they bought something. I now wonder how to do that. I think there are two options:

  1. Create a table in my DB in which I store the emails which I plan to send. So I simply store the customer email address and the date on which I want to send it. I then simply run a cron every day and send the emails that need to be sent and set the status in the table to "sent". The advantage of this method is that I know which emails need to be sent. The disadvantage is that I'm less flexible; it's not easy to change the number of days after which I send the emails because they are stored in the DB.
  2. I can also do it from the code by simply running a cron that gets the list of customers who bought something an x number of days ago, send them the email, and only then store the fact that I sent them an email in the database. The advantage of this method is that I'm more flexible. If I want to send out the emails later I can simply define that in the code (or some var). The disadvantage is that I don't have a list of emails which are going to be sent (although I don't really know what that would be useful for).

My question is actually; what is best practice in this case? How do most websites handle this and why?

  • 写回答

2条回答 默认 最新

  • dongxu7408 2017-02-08 07:36
    关注

    I would choose method 2.

    The disadvantage is not really a disavantage. Supposing you got an "order" table, you can get the list of mail to send just making a query quite similar the one used by your cron.

    But it is a personal choice. I don't know which method is normally used.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图