From 7bf2a27319cf9b2bd5106c5e115c0a00166aa218 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Tue, 1 Sep 2020 19:17:01 +0100 Subject: [PATCH] Track partition offsets and only log unsafe for non-selects --- internal/sqlutil/trace.go | 4 ++-- syncapi/storage/sqlite3/syncserver.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/internal/sqlutil/trace.go b/internal/sqlutil/trace.go index dd92daf68..c3892aac5 100644 --- a/internal/sqlutil/trace.go +++ b/internal/sqlutil/trace.go @@ -53,7 +53,7 @@ func (in *traceInterceptor) StmtQueryContext(ctx context.Context, stmt driver.St safe = w.Safe() } } - if safe != "" { + if safe != "" && !strings.HasPrefix(query, "SELECT ") { logrus.Infof("unsafe: %s -- %s", safe, query) } @@ -75,7 +75,7 @@ func (in *traceInterceptor) StmtExecContext(ctx context.Context, stmt driver.Stm safe = w.Safe() } } - if safe != "" { + if safe != "" && !strings.HasPrefix(query, "SELECT ") { logrus.Infof("unsafe: %s -- %s", safe, query) } diff --git a/syncapi/storage/sqlite3/syncserver.go b/syncapi/storage/sqlite3/syncserver.go index 135495a50..c7530d3cc 100644 --- a/syncapi/storage/sqlite3/syncserver.go +++ b/syncapi/storage/sqlite3/syncserver.go @@ -258,3 +258,16 @@ func (d *SyncServerDatasource) PutFilter(ctx context.Context, localpart string, func (d *SyncServerDatasource) RedactEvent(ctx context.Context, redactedEventID string, redactedBecause *gomatrixserverlib.HeaderedEvent) error { return d.Database.RedactEvent(d.dbctx, redactedEventID, redactedBecause) } + +func (d *SyncServerDatasource) PartitionOffsets( + ctx context.Context, topic string, +) ([]sqlutil.PartitionOffset, error) { + return d.PartitionOffsetStatements.PartitionOffsets(d.dbctx, topic) +} + +// SetPartitionOffset implements PartitionStorer +func (d *SyncServerDatasource) SetPartitionOffset( + ctx context.Context, topic string, partition int32, offset int64, +) error { + return d.PartitionOffsetStatements.SetPartitionOffset(d.dbctx, topic, partition, offset) +}