Skip to content

Commit

Permalink
Implement Collection.Compact for SQLite (#3536)
Browse files Browse the repository at this point in the history
Closes #3469.
  • Loading branch information
Akhil-2001 committed Oct 11, 2023
1 parent 57e283c commit 2d57d3f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
1 change: 0 additions & 1 deletion internal/backends/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ func TestCollectionStats(t *testing.T) {

func TestCollectionCompact(t *testing.T) {
t.Skip("https://github.com/FerretDB/FerretDB/issues/3484")
t.Skip("https://github.com/FerretDB/FerretDB/issues/3469")

t.Parallel()

Expand Down
28 changes: 27 additions & 1 deletion internal/backends/sqlite/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,33 @@ func (c *collection) Stats(ctx context.Context, params *backends.CollectionStats

// Compact implements backends.Collection interface.
func (c *collection) Compact(ctx context.Context, params *backends.CompactParams) (*backends.CompactResult, error) {
// TODO https://github.com/FerretDB/FerretDB/issues/3469
var err error
q := `PRAGMA incremental_vacuum`

db := c.r.DatabaseGetExisting(ctx, c.dbName)
if db == nil {
return nil, backends.NewError(
backends.ErrorCodeDatabaseDoesNotExist,
lazyerrors.Errorf("no ns %s.%s", c.dbName, c.name),
)
}

coll := c.r.CollectionGet(ctx, c.dbName, c.name)
if coll == nil {
return nil, backends.NewError(
backends.ErrorCodeCollectionDoesNotExist,
lazyerrors.Errorf("no ns %s.%s", c.dbName, c.name),
)
}

if params != nil && params.Full {
q = `VACUUM`
}

if _, err = db.ExecContext(ctx, q); err != nil {
return nil, lazyerrors.Error(err)
}

return new(backends.CompactResult), nil
}

Expand Down

0 comments on commit 2d57d3f

Please sign in to comment.