Skip to content

Commit 7797d54

Browse files
committed
fix
1 parent 0156cd3 commit 7797d54

File tree

2 files changed

+2
-52
lines changed

2 files changed

+2
-52
lines changed

template/stmt.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,9 @@ func (s *customCacheStatement) Exec(args []driver.Value) (driver.Result, error)
9090

9191
func execInsert(queryInfo domains.CachePlanQuery, args []driver.Value) {
9292
table := queryInfo.Insert.Table
93-
normalizedArgs, _ := normalizer.NormalizeArgs(queryInfo.Query)
94-
95-
rows := slices.Chunk(args, len(queryInfo.Insert.Columns))
9693

9794
for _, cache := range cacheByTable[table] {
98-
if cache.uniqueOnly {
99-
// no need to purge
100-
continue
101-
}
102-
103-
selectConditions := cache.info.Conditions
104-
if len(selectConditions) != 1 || len(normalizedArgs.ExtraArgs) != 0 || selectConditions[0].Operator != domains.CachePlanOperator_EQ {
105-
cache.cache.Purge()
106-
continue
107-
}
108-
109-
selectCondition := selectConditions[0]
110-
insertColumnIdx := slices.Index(queryInfo.Insert.Columns, selectCondition.Column)
111-
if insertColumnIdx >= 0 {
112-
// insert query is like "INSERT INTO table (col1, col2, ...) VALUES (?, ?, ...)"
113-
// select query is like "SELECT * FROM table WHERE col1 = ?"
114-
// forget the cache
115-
for row := range rows {
116-
cache.cache.Forget(cacheKey([]driver.Value{row[insertColumnIdx]}))
117-
}
118-
} else {
119-
cache.cache.Purge()
120-
}
95+
cache.cache.Purge()
12196
}
12297
}
12398

template/stmt.tmpl

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,9 @@ func (s *customCacheStatement) Exec(args []driver.Value) (driver.Result, error)
9090

9191
func execInsert(queryInfo domains.CachePlanQuery, args []driver.Value) {
9292
table := queryInfo.Insert.Table
93-
normalizedArgs, _ := normalizer.NormalizeArgs(queryInfo.Query)
94-
95-
rows := slices.Chunk(args, len(queryInfo.Insert.Columns))
9693

9794
for _, cache := range cacheByTable[table] {
98-
if cache.uniqueOnly {
99-
// no need to purge
100-
continue
101-
}
102-
103-
selectConditions := cache.info.Conditions
104-
if len(selectConditions) != 1 || len(normalizedArgs.ExtraArgs) != 0 || selectConditions[0].Operator != domains.CachePlanOperator_EQ {
105-
cache.cache.Purge()
106-
continue
107-
}
108-
109-
selectCondition := selectConditions[0]
110-
insertColumnIdx := slices.Index(queryInfo.Insert.Columns, selectCondition.Column)
111-
if insertColumnIdx >= 0 {
112-
// insert query is like "INSERT INTO table (col1, col2, ...) VALUES (?, ?, ...)"
113-
// select query is like "SELECT * FROM table WHERE col1 = ?"
114-
// forget the cache
115-
for row := range rows {
116-
cache.cache.Forget(cacheKey([]driver.Value{row[insertColumnIdx]}))
117-
}
118-
} else {
119-
cache.cache.Purge()
120-
}
95+
cache.cache.Purge()
12196
}
12297
}
12398

0 commit comments

Comments
 (0)