我能优化这个过程吗? [英] Can i optimize this process?

查看:88
本文介绍了我能优化这个过程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我想优化大型电子邮件HTML中SQL子字符串替换的过程。该过程用于构建客户电子邮件html构建,对于10万条记录需要2天。有基本的电子邮件HTML,包含各种占位符和变量,如3个图像,4种不同类型的文本和链接。这些替换在存储过程中的SQL端完成。你能否提出一些建议来优化这个处理时间。

提前感谢您的帮助。



问候,

-Amey





更新:来自评论

嘿Andy感谢您的回复..这里是,下面,我用于HTML替换过程的一个示例SQL。



 更新 EL 
SET LayoutHTMLActual =
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE)(REPLACE(REPLACE)(REPLACE(REPLACE) (REPLACE(REPLACE(REPLACE(EL.LayoutHTMLActual,' {TextID1}',ISNULL(EL) .BodyText,' ')),' {TextID2}',ISNULL(EL.BodyText2,' ')),' {TextID3}',ISNULL(EL.BodyText3,' ')),' {TextID4}',ISNULL(EL.BodyText4, )), {TextID5}',ISNULL(EL.BodyText5,' ') ),' {TextID6}',ISNULL(EL.BodyText6,' ')),' {TextID7}',ISNULL(EL.BodyText7,' ')),' {TextID8}',ISNULL(EL.BodyText8,' ')),' {TextID9}',ISNULL(EL.BodyText9,' ')),' {TextID10}',ISNULL(EL.BodyText10 ,' ')),' < span class =code-string> {TextID11}',ISNULL(EL.BodyText11,' ' )),' {TextID12}',ISNULL(EL.BodyText12,' ')),' {TextID13}',ISNULL(EL.BodyText13,' ' )),' {TextID14}',ISNULL(EL.BodyText14,' )) FROM LayoutPreview EL WITH NOLOCK
WHERE FileID = @ FileID (LayoutName like ' %STD%' OR EL.LayoutName LIKE ' %LAP%'
AND IsValidated = 0





没有使用此类查询,这些查询是针对10万条记录的。即如果记录IsValidated = 0的标志,那么将考虑这些记录。



预先感谢您的帮助。



我尝试了什么:



我尝试过SQL中的替换函数来替换这些占位符和变量。我更新了每个占位符和变量的主HTML列。

解决方案

如果你需要为每条记录自定义一个模板,那么你必须使用你的方法使用(还有其他优化方法,但它只是1模板解决方案的解决方案)。



如果你使用相同的模板,那么你应该只需要在一个字符串中搜索占位符文本,而不是每行都搜索一次。



这里我处理了你的数据结构。您应该做什么创建一个您将加入或选择的模板表。



如上所述,如果需要根据(记录?)自定义某些模板,则可以创建模板覆盖表。这会减慢整个事情,但如果你只有1%的自定义,那么它会减慢0.9%^ _ ^



  DECLARE   @ htmlTemplate   NVARCHAR (MAX) 

set @ htmlTemplate =(选择 top 1 LayoutHTMLActual 来自 EL)

更新 EL
SET LayoutHTMLActual =
REPLACE(替换(替换(替换(替换(替换(替换(替换(替换(替换(替换(替换(替换(替换( @ htmlTemplate ' {TextID1}',ISNULL(EL.BodyText,' ')),' {TextID2}',ISNULL(EL.BodyText2 ,' ')),' < span class =code-string> {TextID3}',ISNULL(EL.BodyText3,' ' )),' {TextID4}',ISNULL(EL.BodyText4,' ')),' {TextID5}',ISNULL(EL.BodyText5,' ' )),' {TextID6}',ISNULL(EL.BodyText6,' )), {TextID7}',ISNULL(EL.BodyText7,' ')),' {TextID8}' ,ISNULL(EL.BodyText8,' ')), ' {TextID9}',ISNULL(EL.BodyText9,' ')),' {TextID10}',ISNULL(EL .BodyText10,' ')),' {TextID11}',ISNULL(EL.BodyText11,' ')),' {TextID12}',ISNULL(EL.BodyText12,< span class =code-string>' ')),' {TextID13}',ISNULL(EL.BodyText13,' ')),' {TextID14}',ISNULL(EL.BodyText14,' ')) FROM LayoutPreview EL WITH NOLOCK
WHERE FileID = @ FileID (LayoutName like ' %STD%' EL.LayoutName LIKE ' %LAP%'
AND IsValidated = 0


Hello All,

I want to optimize the process of SQL sub string replacement in big email HTML. The process is used to build customer email html building, which is taking 2 days for 100 thousands records. There is basic email HTML with various placeholders and variables like 3 images, 4 different types of texts and links. These replacement done at SQL side in stored procedures. Could you please suggest anything to optimize this process time.
Thank you in advance for your help.

Regards,
-Amey


UPDATE: from comments
Hey Andy Thanks for replying.. here is, below, one example SQL which I am using for my HTML replacing process.

UPDATE EL
SET LayoutHTMLActual=
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(EL.LayoutHTMLActual,'{TextID1}',ISNULL(EL.BodyText,'')),'{TextID2}',ISNULL(EL.BodyText2,'')),'{TextID3}',ISNULL(EL.BodyText3,'')),'{TextID4}',ISNULL(EL.BodyText4,'')),'{TextID5}',ISNULL(EL.BodyText5,'')),'{TextID6}',ISNULL(EL.BodyText6,'')),'{TextID7}',ISNULL(EL.BodyText7,'')),'{TextID8}',ISNULL(EL.BodyText8,'')),'{TextID9}',ISNULL(EL.BodyText9,'')),'{TextID10}',ISNULL(EL.BodyText10,'')),'{TextID11}',ISNULL(EL.BodyText11,'')),'{TextID12}',ISNULL(EL.BodyText12,'')),'{TextID13}',ISNULL(EL.BodyText13,'')),'{TextID14}',ISNULL(EL.BodyText14,'')) FROM LayoutPreview EL WITH(NOLOCK)
WHERE FileID=@FileID and (LayoutName like '%STD%' OR EL.LayoutName LIKE '%LAP%')
AND IsValidated = 0



There are no of such queries have been used and these are for 100 thousands of records. i.e If the flag for the record "IsValidated=0" then such records would be considered.

Thanks in advance for your help.

What I have tried:

I have tried just the replace function from SQL to replace these place holders and variables. I updates the main HTML column for every place holder and variable.

解决方案

If you have need to customize a template per record, then you would have to use the approach you use (there are other ways to optimize, but it would just be a work-around for the 1 template solution).

If you use the same template then you should only have to search for the placeholder text one in one string, rather than doing it for every row.

Here I have worked around your data structure. What you should do it create a templates table that you would join, or select from.

As I mentioned above, if some of the templates needed to be customized per (record?) then you could create an template override table. That would slow the whole thing down but if you only have 1% custom then it would slow things down by 0.9% ^_^

DECLARE @htmlTemplate NVARCHAR(MAX)

set @htmlTemplate = (select top 1 LayoutHTMLActual from EL)

UPDATE EL
SET LayoutHTMLActual=
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(@htmlTemplate,'{TextID1}',ISNULL(EL.BodyText,'')),'{TextID2}',ISNULL(EL.BodyText2,'')),'{TextID3}',ISNULL(EL.BodyText3,'')),'{TextID4}',ISNULL(EL.BodyText4,'')),'{TextID5}',ISNULL(EL.BodyText5,'')),'{TextID6}',ISNULL(EL.BodyText6,'')),'{TextID7}',ISNULL(EL.BodyText7,'')),'{TextID8}',ISNULL(EL.BodyText8,'')),'{TextID9}',ISNULL(EL.BodyText9,'')),'{TextID10}',ISNULL(EL.BodyText10,'')),'{TextID11}',ISNULL(EL.BodyText11,'')),'{TextID12}',ISNULL(EL.BodyText12,'')),'{TextID13}',ISNULL(EL.BodyText13,'')),'{TextID14}',ISNULL(EL.BodyText14,'')) FROM LayoutPreview EL WITH(NOLOCK)
WHERE FileID=@FileID and (LayoutName like '%STD%' OR EL.LayoutName LIKE '%LAP%')
AND IsValidated = 0


这篇关于我能优化这个过程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆