Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pirosiki197 committed Jan 26, 2025
1 parent 0156cd3 commit 7797d54
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 52 deletions.
27 changes: 1 addition & 26 deletions template/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,9 @@ func (s *customCacheStatement) Exec(args []driver.Value) (driver.Result, error)

func execInsert(queryInfo domains.CachePlanQuery, args []driver.Value) {
table := queryInfo.Insert.Table
normalizedArgs, _ := normalizer.NormalizeArgs(queryInfo.Query)

rows := slices.Chunk(args, len(queryInfo.Insert.Columns))

for _, cache := range cacheByTable[table] {
if cache.uniqueOnly {
// no need to purge
continue
}

selectConditions := cache.info.Conditions
if len(selectConditions) != 1 || len(normalizedArgs.ExtraArgs) != 0 || selectConditions[0].Operator != domains.CachePlanOperator_EQ {
cache.cache.Purge()
continue
}

selectCondition := selectConditions[0]
insertColumnIdx := slices.Index(queryInfo.Insert.Columns, selectCondition.Column)
if insertColumnIdx >= 0 {
// insert query is like "INSERT INTO table (col1, col2, ...) VALUES (?, ?, ...)"
// select query is like "SELECT * FROM table WHERE col1 = ?"
// forget the cache
for row := range rows {
cache.cache.Forget(cacheKey([]driver.Value{row[insertColumnIdx]}))
}
} else {
cache.cache.Purge()
}
cache.cache.Purge()
}
}

Expand Down
27 changes: 1 addition & 26 deletions template/stmt.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,34 +90,9 @@ func (s *customCacheStatement) Exec(args []driver.Value) (driver.Result, error)

func execInsert(queryInfo domains.CachePlanQuery, args []driver.Value) {
table := queryInfo.Insert.Table
normalizedArgs, _ := normalizer.NormalizeArgs(queryInfo.Query)

rows := slices.Chunk(args, len(queryInfo.Insert.Columns))

for _, cache := range cacheByTable[table] {
if cache.uniqueOnly {
// no need to purge
continue
}

selectConditions := cache.info.Conditions
if len(selectConditions) != 1 || len(normalizedArgs.ExtraArgs) != 0 || selectConditions[0].Operator != domains.CachePlanOperator_EQ {
cache.cache.Purge()
continue
}

selectCondition := selectConditions[0]
insertColumnIdx := slices.Index(queryInfo.Insert.Columns, selectCondition.Column)
if insertColumnIdx >= 0 {
// insert query is like "INSERT INTO table (col1, col2, ...) VALUES (?, ?, ...)"
// select query is like "SELECT * FROM table WHERE col1 = ?"
// forget the cache
for row := range rows {
cache.cache.Forget(cacheKey([]driver.Value{row[insertColumnIdx]}))
}
} else {
cache.cache.Purge()
}
cache.cache.Purge()
}
}

Expand Down

0 comments on commit 7797d54

Please sign in to comment.