Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Collection.Compact for SQLite #3536

Merged
merged 4 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@

// 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),
)
}

Check warning on line 343 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L334-L343

Added lines #L334 - L343 were not covered by tests

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),
)
}

Check warning on line 351 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L345-L351

Added lines #L345 - L351 were not covered by tests

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

Check warning on line 355 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L353-L355

Added lines #L353 - L355 were not covered by tests

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

Check warning on line 359 in internal/backends/sqlite/collection.go

View check run for this annotation

Codecov / codecov/patch

internal/backends/sqlite/collection.go#L357-L359

Added lines #L357 - L359 were not covered by tests

return new(backends.CompactResult), nil
}

Expand Down