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

Loads current text statically. Faster loading

Former-commit-id: d8982466a6736a191c38eb84a185d9f94cf6c05f [formerly 83a34868f75173681e4eef3a5f600a4c739767ac] [formerly dfa3b885a9d93a3937e58ce9a4c8bfdecf5b2023 [formerly 182389dbb1]]
Former-commit-id: 135a25cfa4f97a3d812a9ddcd9fd26d016698742 [formerly f6c9c85696b25c06fcf5899d064d58b6eba0c0cc]
Former-commit-id: b2d7009ee9ddc1505cc07c461c55ba205756e609
This commit is contained in:
Zack Scholl 2016-02-08 08:37:22 -05:00
parent 0ac24a9e12
commit 7d5842354b
4 changed files with 36 additions and 4 deletions

31
db.go
View File

@ -77,6 +77,37 @@ func hasPassword(title string) (bool, error) {
return hasPassword, nil return hasPassword, nil
} }
func getCurrentText(title string) string {
title = strings.ToLower(title)
currentText := ""
if !open {
return currentText
}
err := db.View(func(tx *bolt.Tx) error {
var err error
b := tx.Bucket([]byte("datas"))
if b == nil {
return fmt.Errorf("db must be opened before loading!")
}
k := []byte(title)
val := b.Get(k)
if val == nil {
return nil
}
var p CowyoData
err = p.decode(val)
if err != nil {
return err
}
currentText = p.CurrentText
return nil
})
if err != nil {
fmt.Printf("Could not get CowyoData: %s", err)
}
return currentText
}
func (p *CowyoData) load(title string) error { func (p *CowyoData) load(title string) error {
title = strings.ToLower(title) title = strings.ToLower(title)
if !open { if !open {

View File

@ -32,6 +32,7 @@ func editNote(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{ c.HTML(http.StatusOK, "index.tmpl", gin.H{
"Title": title, "Title": title,
"ExternalIP": RuntimeArgs.ExternalIP, "ExternalIP": RuntimeArgs.ExternalIP,
"CurrentText": getCurrentText(title),
}) })
} }
} }

View File

@ -54,7 +54,7 @@ $(document).ready(function() {
} }
c.onopen = function(){ c.onopen = function(){
updateText(); // updateText();
updateInterval = setInterval(updateText, pollToGetNewestCopyInterval); updateInterval = setInterval(updateText, pollToGetNewestCopyInterval);
} }
}); });

View File

@ -76,7 +76,7 @@
<textarea autofocus rows=500 class='auto_submit_item' id="emit_data" name="emit_data" placeholder="Start typing, it will save automatically. <textarea autofocus rows=500 class='auto_submit_item' id="emit_data" name="emit_data" placeholder="Start typing, it will save automatically.
Go to cowyo.com/{{ .Title }} to reload this page. Go to cowyo.com/{{ .Title }} to reload this page.
Do not post anything private. Do not post anything private.
Anyone with the URL can access this note."></textarea> Anyone with the URL can access this note.">{{ .CurrentText }}</textarea>
</div> </div>
</form> </form>