Monorepo for Tangled
0

Configure Feed

Select the types of activity you want to include in your feed.

appview/pulls: cache combined diffs in 15m lru

Lewis: May this revision serve well! <lewis@tangled.org>

Lewis (Jun 29, 2026, 9:07 PM +0300) b07d141f 804835f8

+24 -3
+10
appview/pulls/pulls.go
··· 7 7 "io" 8 8 "log/slog" 9 9 "strings" 10 + "time" 10 11 11 12 "tangled.org/core/appview/config" 12 13 "tangled.org/core/appview/db" ··· 21 22 "tangled.org/core/idresolver" 22 23 "tangled.org/core/ogre" 23 24 "tangled.org/core/patchutil" 25 + "tangled.org/core/types" 24 26 27 + "github.com/hashicorp/golang-lru/v2/expirable" 25 28 indigoxrpc "github.com/bluesky-social/indigo/xrpc" 26 29 ) 27 30 28 31 const ApplicationGzip = "application/gzip" 29 32 33 + const ( 34 + diffCacheSize = 128 35 + diffCacheTTL = 15 * time.Minute 36 + ) 37 + 30 38 type Pulls struct { 31 39 oauth *oauth.OAuth 32 40 repoResolver *reporesolver.RepoResolver ··· 40 48 logger *slog.Logger 41 49 indexer *pulls_indexer.Indexer 42 50 ogreClient *ogre.Client 51 + diffCache *expirable.LRU[string, types.DiffRenderer] 43 52 } 44 53 45 54 func New( ··· 68 77 logger: logger, 69 78 indexer: indexer, 70 79 ogreClient: ogre.NewClient(config.Ogre.Host), 80 + diffCache: expirable.NewLRU[string, types.DiffRenderer](diffCacheSize, nil, diffCacheTTL), 71 81 } 72 82 } 73 83
+14 -3
appview/pulls/single.go
··· 226 226 vouchSkips[ownerDid] = skipped 227 227 } 228 228 229 - patch := pull.Submissions[roundIdInt].CombinedPatch() 230 229 var diff types.DiffRenderer 231 - diff = patchutil.AsNiceDiff(patch, pull.TargetBranch) 232 - 233 230 if interdiff { 234 231 currentPatch, err := patchutil.AsDiff(pull.Submissions[roundIdInt].CombinedPatch()) 235 232 if err != nil { ··· 246 243 } 247 244 248 245 diff = patchutil.Interdiff(previousPatch, currentPatch) 246 + } else { 247 + diff = s.combinedDiff(pull, roundIdInt) 249 248 } 250 249 251 250 err = s.pages.RepoSinglePull(w, pages.RepoSinglePullParams{ ··· 273 272 if err != nil { 274 273 l.Error("failed to render page", "err", err) 275 274 } 275 + } 276 + 277 + func (s *Pulls) combinedDiff(pull *models.Pull, round int) types.DiffRenderer { 278 + submission := pull.Submissions[round] 279 + key := fmt.Sprintf("%s|%d|%s", pull.AtUri(), round, submission.SourceRev) 280 + if cached, ok := s.diffCache.Get(key); ok { 281 + return cached 282 + } 283 + 284 + diff := patchutil.AsNiceDiff(submission.CombinedPatch(), pull.TargetBranch) 285 + s.diffCache.Add(key, diff) 286 + return diff 276 287 } 277 288 278 289 func (s *Pulls) RepoSinglePull(w http.ResponseWriter, r *http.Request) {