One way to design Message model

Leo posted @ 2011年5月15日 03:50 in OOD with tags design message performance , 10077 阅读

在一般的企业级应用中,Message是一个很常见的应用,其主要目的是可以让系统内的用户(包括系统用户)可以交流(包括attachment)。

如何去设计一个Message  BE(Business Model)模型?

首先会想到一种简单的做法:

class Message
	attr_accessor(:subject, :content, :readDate,:sender,:isReaded,:recipients,:attachments)
end

这种做法的好处就是简单明了,将所有信息全部都放在了Message 上,检索数据的SQL语句也会写的比较简单。但是这样的设计在系统使用一段时间就会发现系统的performance越来越差!究其原因,是因为每条Message在发出去时都会复制给所有的recipients,造成Message entity膨胀过快,导致performance 降低。

那我们改进的方法就是要避免message的过度增长,分析上面的模型,我们发现如果将isReaded、readDate和recipients抽成一个新entity,似乎就可以避免Message的复制。如下图示:

其中Recipient 中存储消息的接收人,这样在s1发送一条消息M发给r1,r2.r3时,只会产生如下Entity:

 One Sender,

 One Message,

Three Recipient

(其他entity可以暂时忽略掉)

如果sender或者recipient 要删除自己的message时,只需要将自身相应的IsDeleted设置为true即可(想想为什么不能直接删除entity?:)

模型的主要设计思路到此为止。

关于当前项目中出现的一些特殊需求,比如:

Kayla给自己的tax contact发的消息应该自动被kayla所属client的所有tax contacts共享。

这个其实只需要在发送邮件时自动bcc给其他tax contacts 就OK了。

Avatar_small
carpet cleaning duba 说:
2019年10月14日 14:31

We offer a myriad of cleaning providers like workplace, carpet, couch, curtain, dried out cleaning, deep cleansing in Dubai plus much more. We value client satisfaction to the greatest level and supply consistent cleansing in Dubai. We offer customized planned cleaning providers in Dubai to the customers.

Avatar_small
maids in dubai 说:
2021年9月16日 14:54

That foremost thing that you require is to help you vacuum and sweep to start with. Do it without liquid. Sweep off the dirt in order that it can steer clear of from to be sticky on the floor or to be muddy. Begin from the aspects and work at a systematic option. If you now have the vacuum purifier, then you might use it. Often, a broomstick is totally fine. Broomsticks vary according with your floor.

Avatar_small
live in maids dubai 说:
2021年9月29日 16:47

Individuals that own the companies gained away with the help of skimping concerning janitorial not to mention professional more refined services for years. Companies a fair distance used for you to do their have dirty give good results having clinic managers prevent the floors tidy and secretaries cover the dusting. Professional chemicals were reserved for ones very good sized companies who owned skyscrapers in your city. Very pretty much never did we can see a the mother and go shop hire in any janitor, cleaning service service and / or professional industry cleaning producers.

Avatar_small
monthly maid service 说:
2023年8月30日 16:35

Inquire of what screening and criminal record searches the cleaning service company runs on workforce. Ask in case the maids will be employees and also subcontractors of your maid company. A cleaning service service working with subcontractors is often more precarious. These persons are often not essential to are accountable to work every particular time frame, might can’t you create the exercising employees currently have, and insurance cover liability is often sketchy.

Avatar_small
maids in dubai 说:
2023年8月30日 16:53

Superior is relative to the expense. If the prospect believes that your painting guesstimate is overly low they likely might are convinced the shade contractor is certainly either decreased balling, inexperienced or simply cutting rates by cheapening the duty in a roundabout way or one other. The customer will then believe that they can be not getting the best value from the fact that paint estimate and definitely will not however , from the fact that contractor regardless if the price is lower.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter