From 4eb885ef385f278ddc52aa4fd000d7abfbe9ef9d Mon Sep 17 00:00:00 2001 From: Adit Sachde <23707194+aditsachde@users.noreply.github.com> Date: Sat, 28 Sep 2024 21:26:38 -0400 Subject: [PATCH] use constant for maxGetEntry --- internal/ctmonitor/fastly.go | 2 +- internal/ctmonitor/fetch.go | 12 +++++++----- internal/ctmonitor/logic.go | 7 ++++--- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/ctmonitor/fastly.go b/internal/ctmonitor/fastly.go index cee126c..75c3c5b 100644 --- a/internal/ctmonitor/fastly.go +++ b/internal/ctmonitor/fastly.go @@ -51,7 +51,7 @@ func FastlyServe(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Reque cache: make(map[string]*CacheEntry), requests: 0, } - f := newFetch(s, maskSize) + f := newFetch(s, maskSize, 75) // Limit get-entries to 75 if r.URL.Path == "/ct/v1/get-sth-consistency" { FastlyWrapper(f.get_sth_consistency)(ctx, w, r) diff --git a/internal/ctmonitor/fetch.go b/internal/ctmonitor/fetch.go index f4fd241..7829100 100644 --- a/internal/ctmonitor/fetch.go +++ b/internal/ctmonitor/fetch.go @@ -13,14 +13,16 @@ import ( ) type Fetch struct { - s Storage - maskSize int + s Storage + maskSize int + maxGetEntry int } -func newFetch(storage Storage, maskSize int) Fetch { +func newFetch(storage Storage, maskSize, maxGetEntry int) Fetch { return Fetch{ - s: storage, - maskSize: maskSize, + s: storage, + maskSize: maskSize, + maxGetEntry: maxGetEntry, } } diff --git a/internal/ctmonitor/logic.go b/internal/ctmonitor/logic.go index 09048ba..b2eccfc 100644 --- a/internal/ctmonitor/logic.go +++ b/internal/ctmonitor/logic.go @@ -22,13 +22,14 @@ import ( // TODO: Evaluate if the context is actually needed func Start(ctx context.Context, tileStoreDir string, tileStoreUrl string, maskSize int) (http.Handler, error) { var f Fetch + maxGetEntry := 1024 if tileStoreDir != "" { storage := &FsStorage{root: tileStoreDir} - f = newFetch(storage, maskSize) + f = newFetch(storage, maskSize, maxGetEntry) } else { storage := &UrlStorage{urlPrefix: tileStoreUrl} - f = newFetch(storage, maskSize) + f = newFetch(storage, maskSize, maxGetEntry) } // Wrap the HTTP handler function with OTel instrumentation @@ -282,7 +283,7 @@ func (f Fetch) get_entries(ctx context.Context, reqBody io.ReadCloser, query url } // Limit the number of entries fetched at once - const limit = 75 + limit := int64(f.maxGetEntry) if end-start > limit { end = start + limit }