在哪里进行转换 - 时区、计量单位等
应该在代码中哪里进行转换? 客户端、服务器、业务还是数据库?
我们目前在数据库中进行时区和计量单位的转换,性能正在让我们崩溃,并且希望移动逻辑。 您认为这样做的最佳位置是哪里?
谢谢
Where in code should conversions be done? client, server, business, or db?
We currently do conversions of timezones and unit of measure in our database and the performance is killing us and would like to move the logic. Where do you think the best location for this is?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我肯定会从数据库中获取该代码。 您希望尽可能将数据全部存储在一组通用的单位中。 为某一特定区域(通常是您自己的区域)存储时间数据是很常见的。
我也不会将其放在业务层中,因为这样您将遇到必须使用来自不同区域设置的时间进行计算的情况,并且您需要它们具有相同的起始引用。 同样,您应该将它们全部保留在一个共同的基础上,这里最合乎逻辑的事情就是让该基础成为您存储它们的任何区域设置。
我认为最合乎逻辑的做法是将时间转换为用户的时间区域设置在最后一刻,就在显示之前。 这将它牢牢地置于 GUI 层。
I would definitely get that code out of the DB. You want to store data all in a common set of units whenever you can. Having your time data stored for one specific locale (usually your own) is common.
I wouldn't put it in the business tier either, because then you'll run into situations where you have to do calculations using times from different locales, and you'll need them to have the same starting reference. Again, you should leave them all at a common base, and the most logical thing here is to just let that base be whatever locale you're storing them in.
I think the most logical thing to do is to have time converted to the user's locale at the last possible moment, right before you display it. This puts it firmly in the GUI layer.
通常这些是客户端/UI 选择。 但该偏好可以传递到服务器或业务规则。
我会在客户端中执行此操作,以标准化其他地方的数据。
编辑:
如果您有一个非常瘦的客户端并且不想向其添加逻辑,那么找到您有代码/规则/等的下一个位置并将它们添加到那里。 找到最外层/客户端代码并将其放在一起。
Typically those are client/UI choices. but that preference can be passed to the server or the business rules.
I would do it in the client to normalize data everywhere else.
EDIT:
If you have a really thin client and do not want to add logic to it, then find the next place where you have code/rules/etc and add them there. Find the outermost/client side code and put it with that.
我们正在尝试“尽可能早地”完成这些任务(在我们的例子中,这是客户端连接的地方),并在服务器上端到端地使用统一的数据。 当然,当发送回来时,数据会被适当地转换。
We are trying to do them "as early as it is possible" (in our case it is where clients are connected) and work with unified data end-to-end on a server. Of course, when sent back, data is converted appropriately.
我不确定你所说的“转换”是什么意思。 如果您指的是本地化,那么传统上是在 GUI 层完成的。
I'm not sure what you mean by "conversions." If you mean localization, then that is traditionally done in the GUI layer.