loading up the forgejo repo on tangled to test page performance
at forgejo 63 lines 1.5 kB view raw
1// Copyright 2020 The Gitea Authors. All rights reserved. 2// SPDX-License-Identifier: MIT 3 4package middleware 5 6import ( 7 "context" 8 "time" 9 10 "forgejo.org/modules/setting" 11) 12 13// ContextDataStore represents a data store 14type ContextDataStore interface { 15 GetData() ContextData 16} 17 18type ContextData map[string]any 19 20func (ds ContextData) GetData() ContextData { 21 return ds 22} 23 24func (ds ContextData) MergeFrom(other ContextData) ContextData { 25 for k, v := range other { 26 ds[k] = v 27 } 28 return ds 29} 30 31const ContextDataKeySignedUser = "SignedUser" 32 33type contextDataKeyType struct{} 34 35var contextDataKey contextDataKeyType 36 37func WithContextData(c context.Context) context.Context { 38 return context.WithValue(c, contextDataKey, make(ContextData, 10)) 39} 40 41func GetContextData(c context.Context) ContextData { 42 if ds, ok := c.Value(contextDataKey).(ContextData); ok { 43 return ds 44 } 45 return nil 46} 47 48func CommonTemplateContextData() ContextData { 49 return ContextData{ 50 "IsLandingPageOrganizations": setting.LandingPageURL == setting.LandingPageOrganizations, 51 52 "ShowRegistrationButton": setting.Service.ShowRegistrationButton, 53 "ShowMilestonesDashboardPage": setting.Service.ShowMilestonesDashboardPage, 54 "ShowFooterVersion": setting.Other.ShowFooterVersion, 55 "DisableDownloadSourceArchives": setting.Repository.DisableDownloadSourceArchives, 56 57 "EnableSwagger": setting.API.EnableSwagger, 58 "EnableOpenIDSignIn": setting.Service.EnableOpenIDSignIn, 59 "PageStartTime": time.Now(), 60 61 "RunModeIsProd": setting.IsProd, 62 } 63}