Skip to content

Commit 08c6d19

Browse files
committed
Fix statement ignore
1 parent 9b4a570 commit 08c6d19

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

plugin/plugin.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,11 @@ func (p *Plugin) invalidateDML(ctx context.Context, query string) {
247247
p.Logger.Trace("Query message", "query", queryMessage)
248248

249249
queryString := strings.ToUpper(queryMessage["String"])
250-
// TODO: Add change detection for all changes to DB, not just for the DMLs.
251-
// https://github.com/gatewayd-io/gatewayd-plugin-cache/issues/19
252-
if !strings.HasPrefix(queryString, "UPDATE") ||
253-
!strings.HasPrefix(queryString, "INSERT") ||
254-
!strings.HasPrefix(queryString, "DELETE") {
255-
p.Logger.Debug("Query is not a DML. Skipping invalidation")
250+
// Ignore SELECT and WITH/SELECT queries.
251+
// TODO: This is a naive approach, but query parsing has a cost.
252+
if strings.HasPrefix(queryString, "SELECT") ||
253+
(strings.HasPrefix(queryString, "WITH") &&
254+
strings.Contains(queryString, "SELECT")) {
256255
return
257256
}
258257

0 commit comments

Comments
 (0)