mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-28 22:19:59 +02:00
Fix some server rebuild issues for non-HTML custom output formats
The failing test case here is * A custom search output format defined on the home page, marked as `noAlternative` and not `permalinkable` * In fast render mode, when making a change to a data source for that search output format, the JSON file was not refreshed. There are variants of the above, but the gist of it is: * The change set was correctly determined, but since the search JSON file was not in the recently visited browser stack, we skipped rendering it. Running with `hugo server --disableFastRender` would be a workaround for the above. This commit fixes this by: * Adding a check for the HTTP request header `Sec-Fetch-Mode = navigation` to the condition for if we should track server request as a user navigation (and not e.g. a HTTP request for a linked CSS stylesheet). * Making sure that we compare against the real relative URL for non-permalinkable output formats. Fixes #13014
This commit is contained in:
@@ -18,24 +18,24 @@ import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// EvictingStringQueue is a queue which automatically evicts elements from the head of
|
||||
// EvictingQueue is a queue which automatically evicts elements from the head of
|
||||
// the queue when attempting to add new elements onto the queue and it is full.
|
||||
// This queue orders elements LIFO (last-in-first-out). It throws away duplicates.
|
||||
// Note: This queue currently does not contain any remove (poll etc.) methods.
|
||||
type EvictingStringQueue struct {
|
||||
type EvictingQueue[T comparable] struct {
|
||||
size int
|
||||
vals []string
|
||||
set map[string]bool
|
||||
vals []T
|
||||
set map[T]bool
|
||||
mu sync.Mutex
|
||||
zero T
|
||||
}
|
||||
|
||||
// NewEvictingStringQueue creates a new queue with the given size.
|
||||
func NewEvictingStringQueue(size int) *EvictingStringQueue {
|
||||
return &EvictingStringQueue{size: size, set: make(map[string]bool)}
|
||||
// NewEvictingQueue creates a new queue with the given size.
|
||||
func NewEvictingQueue[T comparable](size int) *EvictingQueue[T] {
|
||||
return &EvictingQueue[T]{size: size, set: make(map[T]bool)}
|
||||
}
|
||||
|
||||
// Add adds a new string to the tail of the queue if it's not already there.
|
||||
func (q *EvictingStringQueue) Add(v string) *EvictingStringQueue {
|
||||
func (q *EvictingQueue[T]) Add(v T) *EvictingQueue[T] {
|
||||
q.mu.Lock()
|
||||
if q.set[v] {
|
||||
q.mu.Unlock()
|
||||
@@ -54,7 +54,7 @@ func (q *EvictingStringQueue) Add(v string) *EvictingStringQueue {
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *EvictingStringQueue) Len() int {
|
||||
func (q *EvictingQueue[T]) Len() int {
|
||||
if q == nil {
|
||||
return 0
|
||||
}
|
||||
@@ -64,7 +64,7 @@ func (q *EvictingStringQueue) Len() int {
|
||||
}
|
||||
|
||||
// Contains returns whether the queue contains v.
|
||||
func (q *EvictingStringQueue) Contains(v string) bool {
|
||||
func (q *EvictingQueue[T]) Contains(v T) bool {
|
||||
if q == nil {
|
||||
return false
|
||||
}
|
||||
@@ -74,12 +74,12 @@ func (q *EvictingStringQueue) Contains(v string) bool {
|
||||
}
|
||||
|
||||
// Peek looks at the last element added to the queue.
|
||||
func (q *EvictingStringQueue) Peek() string {
|
||||
func (q *EvictingQueue[T]) Peek() T {
|
||||
q.mu.Lock()
|
||||
l := len(q.vals)
|
||||
if l == 0 {
|
||||
q.mu.Unlock()
|
||||
return ""
|
||||
return q.zero
|
||||
}
|
||||
elem := q.vals[l-1]
|
||||
q.mu.Unlock()
|
||||
@@ -87,9 +87,12 @@ func (q *EvictingStringQueue) Peek() string {
|
||||
}
|
||||
|
||||
// PeekAll looks at all the elements in the queue, with the newest first.
|
||||
func (q *EvictingStringQueue) PeekAll() []string {
|
||||
func (q *EvictingQueue[T]) PeekAll() []T {
|
||||
if q == nil {
|
||||
return nil
|
||||
}
|
||||
q.mu.Lock()
|
||||
vals := make([]string, len(q.vals))
|
||||
vals := make([]T, len(q.vals))
|
||||
copy(vals, q.vals)
|
||||
q.mu.Unlock()
|
||||
for i, j := 0, len(vals)-1; i < j; i, j = i+1, j-1 {
|
||||
@@ -99,9 +102,9 @@ func (q *EvictingStringQueue) PeekAll() []string {
|
||||
}
|
||||
|
||||
// PeekAllSet returns PeekAll as a set.
|
||||
func (q *EvictingStringQueue) PeekAllSet() map[string]bool {
|
||||
func (q *EvictingQueue[T]) PeekAllSet() map[T]bool {
|
||||
all := q.PeekAll()
|
||||
set := make(map[string]bool)
|
||||
set := make(map[T]bool)
|
||||
for _, v := range all {
|
||||
set[v] = true
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@ import (
|
||||
func TestEvictingStringQueue(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
queue := NewEvictingStringQueue(3)
|
||||
queue := NewEvictingQueue[string](3)
|
||||
|
||||
c.Assert(queue.Peek(), qt.Equals, "")
|
||||
queue.Add("a")
|
||||
@@ -53,7 +53,7 @@ func TestEvictingStringQueueConcurrent(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
val := "someval"
|
||||
|
||||
queue := NewEvictingStringQueue(3)
|
||||
queue := NewEvictingQueue[string](3)
|
||||
|
||||
for j := 0; j < 100; j++ {
|
||||
wg.Add(1)
|
||||
|
Reference in New Issue
Block a user