From 0665511954426da1d72b10c555b1ca2b1cf54544 Mon Sep 17 00:00:00 2001
From: Jean-Paul Calderone <exarkun@twistedmatrix.com>
Date: Thu, 10 Sep 2020 14:34:01 -0400
Subject: [PATCH] Combine the tokens before doing expensive things to them

It seems to be faster to hash one huge string than many smaller ones that
total to the same length.  Also by only showing one final hash we remove O(N)
show calls.

The old and new fingerprints are not compatible but I haven't deployed this
in production anywhere yet so that doesn't bother me.  Had I, we'd need some
kind of versioning scheme for fingerprint computation I suppose.
---
 src/PaymentServer/Redemption.hs | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/PaymentServer/Redemption.hs b/src/PaymentServer/Redemption.hs
index fa2e3a4..6c0cf7b 100644
--- a/src/PaymentServer/Redemption.hs
+++ b/src/PaymentServer/Redemption.hs
@@ -11,6 +11,10 @@ module PaymentServer.Redemption
   , redemptionServer
   ) where
 
+import Prelude hiding
+  ( concat
+  )
+
 import GHC.Generics
   ( Generic
   )
@@ -27,6 +31,7 @@ import Control.Monad.IO.Class
 import Data.Text
   ( Text
   , pack
+  , concat
   )
 import Data.Text.Encoding
   ( encodeUtf8
@@ -211,7 +216,4 @@ redeem issue database (Redeem voucher tokens counter) =
 -- be used as an identifier for this exact sequence of tokens.
 fingerprintFromTokens :: [BlindedToken] -> Fingerprint
 fingerprintFromTokens =
-  let
-    hash = pack . show . hashWith SHA3_512 . encodeUtf8
-  in
-    foldl (\b a -> hash $ a `mappend` b) "" . map hash
+  pack . show . hashWith SHA3_512 . encodeUtf8 . concat
-- 
GitLab