1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Make save mutex per-site

This commit is contained in:
Daniel Heath 2018-04-28 19:32:48 +10:00
parent d9b8bfc95d
commit d48d1458a5
2 changed files with 5 additions and 5 deletions

View File

@ -12,6 +12,7 @@ import (
"path" "path"
"strconv" "strconv"
"strings" "strings"
"sync"
"time" "time"
secretRequired "github.com/danielheath/gin-teeny-security" secretRequired "github.com/danielheath/gin-teeny-security"
@ -39,6 +40,7 @@ type Site struct {
MaxUploadSize uint MaxUploadSize uint
Logger *lumber.ConsoleLogger Logger *lumber.ConsoleLogger
saveMut sync.Mutex
sitemapUpToDate bool // TODO this makes everything use a pointer sitemapUpToDate bool // TODO this makes everything use a pointer
} }
@ -95,6 +97,7 @@ func Serve(
fileuploads, fileuploads,
maxUploadSize, maxUploadSize,
logger, logger,
sync.Mutex{},
false, false,
}.Router() }.Router()

View File

@ -9,7 +9,6 @@ import (
"regexp" "regexp"
"sort" "sort"
"strings" "strings"
"sync"
"time" "time"
"github.com/schollz/versionedtext" "github.com/schollz/versionedtext"
@ -164,11 +163,9 @@ func (p *Page) Render() {
p.RenderedPage = MarkdownToHtml(p.Text.GetCurrent()) p.RenderedPage = MarkdownToHtml(p.Text.GetCurrent())
} }
var saveMut = sync.Mutex{}
func (p *Page) Save() error { func (p *Page) Save() error {
saveMut.Lock() p.Site.saveMut.Lock()
defer saveMut.Unlock() defer p.Site.saveMut.Unlock()
bJSON, err := json.MarshalIndent(p, "", " ") bJSON, err := json.MarshalIndent(p, "", " ")
if err != nil { if err != nil {
return err return err