Skip to content

Commit

Permalink
fix index stats on bulk (#117)
Browse files Browse the repository at this point in the history
* fix index stats on bulk

* add http cache for ui assets

* fix expanded ui

* fix expanded ui

* fix cache for ui assets
  • Loading branch information
hengfeiyang committed Mar 23, 2022
1 parent 9ec6a0a commit 31869dd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/handlers/bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ func BulkHandlerWorker(target string, body io.ReadCloser) (*BulkResponse, error)
batch[indexName].Update(bdoc.ID(), bdoc)
} else {
batch[indexName].Insert(bdoc)
core.ZINC_INDEX_LIST[indexName].GainDocsCount(1)
}

// refresh index stats
core.ZINC_INDEX_LIST[indexName].GainDocsCount(1)

if documentsInBatch >= batchSize {
for _, indexN := range indexesInThisBatch {
// Persist the batch to the index
Expand Down
21 changes: 21 additions & 0 deletions pkg/routes/httpcache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package routes

import (
"strings"
"time"

"github.com/gin-gonic/gin"
)

func HTTPCacheForUI(r *gin.Engine) {
r.Use(func(c *gin.Context) {
if c.Request.Method == "GET" || c.Request.Method == "HEAD" {
if strings.Contains(c.Request.RequestURI, "/ui/assets/") {
c.Writer.Header().Set("cache-control", "public, max-age=2592000")
c.Writer.Header().Set("expires", time.Now().Add(time.Hour*24*30).Format(time.RFC1123))
}
}

c.Next()
})
}
1 change: 1 addition & 0 deletions pkg/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func SetRoutes(r *gin.Engine) {
log.Err(err)
}

HTTPCacheForUI(r)
r.StaticFS("/ui/", http.FS(front))
r.NoRoute(func(c *gin.Context) {
log.Error().
Expand Down
3 changes: 3 additions & 0 deletions web/src/components/search/SearchList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ export default defineComponent({
word-break: break-all;
.expanded {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
word-break: break-all;
}
}
}
Expand Down

0 comments on commit 31869dd

Please sign in to comment.