From a62a09b258506c3cf97de84ca0c487b605c71609 Mon Sep 17 00:00:00 2001 From: Simon Martens Date: Wed, 8 Jan 2025 15:53:44 +0100 Subject: [PATCH] Small comment changes --- kgpz_web.go | 11 ----------- providers/git.go | 11 +++++------ scratchpad.md | 0 server/server.go | 22 ++++++++++++---------- xmlmodels/pieces.go | 30 ------------------------------ 5 files changed, 17 insertions(+), 57 deletions(-) create mode 100644 scratchpad.md diff --git a/kgpz_web.go b/kgpz_web.go index 931f493..b457a56 100644 --- a/kgpz_web.go +++ b/kgpz_web.go @@ -21,17 +21,6 @@ const ( DEV_CONFIG = "config.dev.json" ) -// 1. Check if folder exists -// - If not, clone the repo, if possible or throw if error -// 2. If the folder exists, we try to serialize -- and spawn a goroutine to pull. -// Upon pulling, we read in the current state of the repository, even if it's up to date. -// -> If the repo was changed we execute a callback and parse again. -// -> If pulling fails, we retry after a certain amount of time. -// Still we can continue if serialization proceeds. -// -> If serialization fails, we throw an error, log it. We try to pull in the background. -// - setup commit date & hash -// - Setup GitHub webhook if set - func main() { cfg := providers.NewConfigProvider([]string{DEV_CONFIG, DEFAULT_CONFIG}) if err := cfg.Read(); err != nil { diff --git a/providers/git.go b/providers/git.go index 061850b..4eccfe7 100644 --- a/providers/git.go +++ b/providers/git.go @@ -17,12 +17,11 @@ var InvalidStateError = errors.New("The GitProvider is not in a valid state. Fix var NoURLProvidedError = errors.New("No URL provided for GitProvider.") var NoPathProvidedError = errors.New("No path or branch provided for GitProvider.") -// NOTE: GitProvider does not open XML files, it can only -// - read in information from the repo, given a path -// - clone the repo, given an URL & a path -// - pull the repo, given a path -// In case of success in either case it updates the commit hash and date and closes the repo again. -// The Files are opened and serialized by the FSProvider, which operates on the same file path. +// NOTE: GitProvider does not open any worktree files, it only +// - reads in information from the repo, given a path +// - clones a repo, given an URL & a path +// - pulls a repo, given a path +// In case of success it updates it's state: the commit hash and date. Then it closes the repo. type GitProvider struct { mu sync.Mutex diff --git a/scratchpad.md b/scratchpad.md new file mode 100644 index 0000000..e69de29 diff --git a/server/server.go b/server/server.go index 8bca666..51144cb 100644 --- a/server/server.go +++ b/server/server.go @@ -25,7 +25,8 @@ const ( SERVER_TIMEOUT = 16 * time.Second // INFO: Maybe this is too long/short? - CACHE_TIME = 24 * time.Hour + CACHE_TIME = 24 * time.Hour + CACHE_GC_INTERVAL = 120 * time.Second ) const ( @@ -99,7 +100,7 @@ func (s *Server) Start() { if s.cache == nil { s.cache = memory.New(memory.Config{ - GCInterval: 30 * time.Second, + GCInterval: CACHE_GC_INTERVAL, }) } @@ -117,7 +118,7 @@ func (s *Server) Start() { ErrorHandler: fiber.DefaultErrorHandler, // WARNING: The app must be run in a console, since this uses environment variables: - // It is not trivial to turn this on, since we need to mark goroutines that can be started only once. + // It is not trivial to turn this on, since we need to mark goroutines that must be started only once. // Prefork: true, StreamRequestBody: false, WriteTimeout: REQUEST_TIMEOUT, @@ -138,8 +139,8 @@ func (s *Server) Start() { srv.Use(ASSETS_URL_PREFIX, etag.New()) srv.Use(ASSETS_URL_PREFIX, static(&views.StaticFS)) - // TODO: Dont cache static assets, bc storage gets huge - // INFO: Maybe fiber does this already? + // TODO: Dont cache static assets, bc storage gets huge on images. + // -> Maybe fiber does this already, automatically? if s.Config.Debug { srv.Use(cache.New(cache.Config{ Next: CacheFunc, @@ -156,9 +157,6 @@ func (s *Server) Start() { })) } - // TODO: this is probably a bad idea, since it basically applies to every /XXXX URL - // And probably creates problems with static files, and in case we add a front page later. - // That's why we redirect to /1764 on "/ " and don´t use an optional /:year? srv.Get("/", func(c *fiber.Ctx) error { c.Redirect(INDEX_URL) return nil @@ -168,8 +166,12 @@ func (s *Server) Start() { srv.Get(CATEGORY_OVERVIEW_URL, controllers.GetCategory(s.kgpz)) srv.Get(AGENTS_OVERVIEW_URL, controllers.GetAgents(s.kgpz)) - // TODO: Same here, this prob applies to all paths with two or three segments, which is bad. - // Prob better to do /ausgabe/:year/:issue/:page? here and /jahrgang/:year? above. + // TODO: YEAR_OVERVIEW_URL being /:year is a bad idea, since it captures basically everything, + // probably creating problems with static files, and also in case we add a front page later. + // That's why we redirect to /1764 on "/ " above and don´t use an optional /:year? paramter. + // -> Check SEO requirements on index pages that are 301 forwarded. + // This applies to all paths with two or three segments without a static prefix: + // Prob better to do /ausgabe/:year/:issue/:page? and /jahrgang/:year? respectively. srv.Get(YEAR_OVERVIEW_URL, controllers.GetYear(s.kgpz)) srv.Get(ISSSUE_URL, controllers.GetIssue(s.kgpz)) srv.Get(ADDITIONS_URL, controllers.GetIssue(s.kgpz)) diff --git a/xmlmodels/pieces.go b/xmlmodels/pieces.go index a34f4dc..e7dc75d 100644 --- a/xmlmodels/pieces.go +++ b/xmlmodels/pieces.go @@ -189,33 +189,3 @@ func (p Piece) ReferencesWork(id string) (*WorkRef, bool) { } return nil, false } - -// TODO: We can make this fast depending on which category to look for -// but we'll have to define rules for every single category (~35 of them) -func (p Piece) IsCat(k string) bool { - for _, c := range p.CategoryRefs { - if c.Category == k { - return true - } - } - - for _, c := range p.WorkRefs { - if c.Category == k { - return true - } - } - - for _, c := range p.AgentRefs { - if c.Category == k { - return true - } - } - - for _, c := range p.PieceRefs { - if c.Category == k { - return true - } - } - - return false -}