summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/schema/tables.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-04-15 11:01:20 +0100
committerLibravatar GitHub <noreply@github.com>2024-04-15 12:01:20 +0200
commit1018cde107f8832cafab64f9003dcde0a055899c (patch)
treed676685511306377c419af09e93355c57be760ce /vendor/github.com/uptrace/bun/schema/tables.go
parent[chore]: Bump golang.org/x/net from 0.23.0 to 0.24.0 (#2834) (diff)
downloadgotosocial-1018cde107f8832cafab64f9003dcde0a055899c.tar.xz
[chore] bump bun library versions (#2837)
Diffstat (limited to 'vendor/github.com/uptrace/bun/schema/tables.go')
-rw-r--r--vendor/github.com/uptrace/bun/schema/tables.go61
1 files changed, 26 insertions, 35 deletions
diff --git a/vendor/github.com/uptrace/bun/schema/tables.go b/vendor/github.com/uptrace/bun/schema/tables.go
index b6215a14a..19aff8606 100644
--- a/vendor/github.com/uptrace/bun/schema/tables.go
+++ b/vendor/github.com/uptrace/bun/schema/tables.go
@@ -6,48 +6,19 @@ import (
"sync"
)
-type tableInProgress struct {
- table *Table
-
- init1Once sync.Once
- init2Once sync.Once
-}
-
-func newTableInProgress(table *Table) *tableInProgress {
- return &tableInProgress{
- table: table,
- }
-}
-
-func (inp *tableInProgress) init1() bool {
- var inited bool
- inp.init1Once.Do(func() {
- inp.table.init1()
- inited = true
- })
- return inited
-}
-
-func (inp *tableInProgress) init2() bool {
- var inited bool
- inp.init2Once.Do(func() {
- inp.table.init2()
- inited = true
- })
- return inited
-}
-
type Tables struct {
dialect Dialect
tables sync.Map
mu sync.RWMutex
+ seen map[reflect.Type]*Table
inProgress map[reflect.Type]*tableInProgress
}
func NewTables(dialect Dialect) *Tables {
return &Tables{
dialect: dialect,
+ seen: make(map[reflect.Type]*Table),
inProgress: make(map[reflect.Type]*tableInProgress),
}
}
@@ -62,7 +33,7 @@ func (t *Tables) Get(typ reflect.Type) *Table {
return t.table(typ, false)
}
-func (t *Tables) Ref(typ reflect.Type) *Table {
+func (t *Tables) InProgress(typ reflect.Type) *Table {
return t.table(typ, true)
}
@@ -87,7 +58,7 @@ func (t *Tables) table(typ reflect.Type, allowInProgress bool) *Table {
inProgress := t.inProgress[typ]
if inProgress == nil {
- table = newTable(t.dialect, typ)
+ table = newTable(t.dialect, typ, t.seen, false)
inProgress = newTableInProgress(table)
t.inProgress[typ] = inProgress
} else {
@@ -96,12 +67,11 @@ func (t *Tables) table(typ reflect.Type, allowInProgress bool) *Table {
t.mu.Unlock()
- inProgress.init1()
if allowInProgress {
return table
}
- if !inProgress.init2() {
+ if !inProgress.init() {
return table
}
@@ -149,3 +119,24 @@ func (t *Tables) ByName(name string) *Table {
})
return found
}
+
+type tableInProgress struct {
+ table *Table
+
+ initOnce sync.Once
+}
+
+func newTableInProgress(table *Table) *tableInProgress {
+ return &tableInProgress{
+ table: table,
+ }
+}
+
+func (inp *tableInProgress) init() bool {
+ var inited bool
+ inp.initOnce.Do(func() {
+ inp.table.init()
+ inited = true
+ })
+ return inited
+}