From ac3730fc89e02c00a13cc5313992c130959c0cb4 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Fri, 16 Oct 2026 22:06:07 -1000 Subject: Unwrap an avatar address in linear time An author email of 16,000 "<" took three quarters of a second per log row, and one of 64,000 took twelve seconds. --- custom/extensions/email-libravatar.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'custom/extensions/email-libravatar.lua') diff --git a/custom/extensions/email-libravatar.lua b/custom/extensions/email-libravatar.lua index 2b1fecd..3422dc1 100644 --- a/custom/extensions/email-libravatar.lua +++ b/custom/extensions/email-libravatar.lua @@ -79,9 +79,12 @@ local function normalize_email(email) if email == nil then return nil end - local inner = email:match("<(.*)>") - if inner ~= nil then - email = inner + -- The first "<" and the last ">" are found directly, because "<(.*)>" + -- backtracks to the end of the address from every "<" in it. + local open = email:find("<", 1, true) + local close = email:find(">[^>]*$") + if open and close and close > open then + email = email:sub(open + 1, close - 1) end email = trim(email):lower() if email == "" then -- cgit