Enable WebSocket compression
This commit is contained in:
parent
dace522a6e
commit
1475a98a69
15
main.go
15
main.go
|
@ -74,21 +74,6 @@ func main() {
|
|||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "compact",
|
||||
Aliases: []string{"c"},
|
||||
Usage: "compact all notebook",
|
||||
Action: func(c *cli.Context) error {
|
||||
Initialize(configPath, debug)
|
||||
|
||||
for _, notebook := range stick.Notebooks {
|
||||
notebook.Compact()
|
||||
}
|
||||
|
||||
fmt.Println("notebooks compacted")
|
||||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "resolve",
|
||||
Aliases: []string{"r"},
|
||||
|
|
|
@ -182,7 +182,12 @@ func (n *Notebook) Compact() {
|
|||
tree, err := n.Repository.Worktree()
|
||||
CheckError(err)
|
||||
|
||||
wtroot := tree.Filesystem.Root()
|
||||
|
||||
cmd := exec.Command("git", "-C", tree.Filesystem.Root(), "gc", "--aggressive", "--prune=now")
|
||||
err = cmd.Run()
|
||||
CheckError(err)
|
||||
|
||||
n.Repository, err = LoadRepository(wtroot)
|
||||
CheckError(err)
|
||||
}
|
||||
|
|
35
web.go
35
web.go
|
@ -37,6 +37,7 @@ var upgrader = websocket.Upgrader{
|
|||
CheckOrigin: func(r *http.Request) bool {
|
||||
return true
|
||||
},
|
||||
EnableCompression: true,
|
||||
}
|
||||
|
||||
func printServedNotebooks() {
|
||||
|
@ -201,7 +202,7 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
|
|||
commitMessage = "update"
|
||||
}
|
||||
|
||||
commit, err := wt.Commit(commitMessage+" "+fileName, &git.CommitOptions{
|
||||
_, err = wt.Commit(commitMessage+" "+fileName, &git.CommitOptions{
|
||||
Author: &object.Signature{
|
||||
Name: author.Name,
|
||||
Email: DefaultAuthorEmail,
|
||||
|
@ -210,14 +211,6 @@ func editHandler(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
CheckError(err)
|
||||
|
||||
obj, err := notebook.Repository.CommitObject(commit)
|
||||
CheckError(err)
|
||||
|
||||
if obj == nil {
|
||||
writeStatus(w, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
updateWebSockets(author, nbid, noteID)
|
||||
writeStatus(w, "success")
|
||||
return
|
||||
|
@ -297,7 +290,7 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
_, err = wt.Add(file.Name)
|
||||
CheckError(err)
|
||||
|
||||
commit, err := wt.Commit("delete "+file.Name, &git.CommitOptions{
|
||||
_, err = wt.Commit("delete "+file.Name, &git.CommitOptions{
|
||||
Author: &object.Signature{
|
||||
Name: author.Name,
|
||||
Email: DefaultAuthorEmail,
|
||||
|
@ -306,14 +299,6 @@ func deleteHandler(w http.ResponseWriter, r *http.Request) {
|
|||
})
|
||||
CheckError(err)
|
||||
|
||||
obj, err := notebook.Repository.CommitObject(commit)
|
||||
CheckError(err)
|
||||
|
||||
if obj == nil {
|
||||
writeStatus(w, "fail")
|
||||
return
|
||||
}
|
||||
|
||||
updateWebSockets(author, nbid, note)
|
||||
writeStatus(w, "success")
|
||||
return
|
||||
|
@ -486,6 +471,10 @@ func sendNotesSince(ss *StickSocket, modified int64) int64 {
|
|||
}
|
||||
|
||||
func webSocketCheckItem(ss *StickSocket, data map[string]interface{}) {
|
||||
if stick.Config.Debug {
|
||||
defer elapsed("webSocketCheckItem")()
|
||||
}
|
||||
|
||||
var (
|
||||
notebookID string
|
||||
noteID string
|
||||
|
@ -594,7 +583,7 @@ func webSocketCheckItem(ss *StickSocket, data map[string]interface{}) {
|
|||
_, err = wt.Add(file.Name)
|
||||
CheckError(err)
|
||||
|
||||
commit, err := wt.Commit("update "+file.Name, &git.CommitOptions{
|
||||
_, err = wt.Commit("update "+file.Name, &git.CommitOptions{
|
||||
Author: &object.Signature{
|
||||
Name: ss.Author.Name,
|
||||
Email: DefaultAuthorEmail,
|
||||
|
@ -603,14 +592,6 @@ func webSocketCheckItem(ss *StickSocket, data map[string]interface{}) {
|
|||
})
|
||||
CheckError(err)
|
||||
|
||||
obj, err := notebook.Repository.CommitObject(commit)
|
||||
CheckError(err)
|
||||
|
||||
if obj == nil {
|
||||
failWebSocket(ss.Conn, "failed to update note")
|
||||
return
|
||||
}
|
||||
|
||||
updateWebSockets(ss.Author, notebookID, noteID)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue