Skip to content

Commit

Permalink
add Vacuum func to mapdb
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Feb 19, 2023
1 parent 2f134bc commit 1c55846
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type BlockRepository interface {
GetByPos(x, y, z int) (*Block, error)
Update(block *Block) error
Delete(x, y, z int) error
Vacuum() error
}

func NewBlockRepository(db *sql.DB, dbtype types.DatabaseType) BlockRepository {
Expand Down
5 changes: 5 additions & 0 deletions block/block_postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ func (repo *postgresBlockRepository) Delete(x, y, z int) error {
_, err := repo.db.Exec("delete from blocks where posX=$1 and posY=$2 and posZ=$3", x, y, z)
return err
}

func (repo *postgresBlockRepository) Vacuum() error {
_, err := repo.db.Exec("vacuum")
return err
}
7 changes: 6 additions & 1 deletion block/block_sqlite.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type sqliteBlockRepository struct {
db *sql.DB
}

//https://bitbucket.org/s_l_teichmann/mtsatellite/src/e1bf980a2b278c570b3f44f9452c9c087558acb3/common/coords.go?at=default&fileviewer=file-view-default
// https://bitbucket.org/s_l_teichmann/mtsatellite/src/e1bf980a2b278c570b3f44f9452c9c087558acb3/common/coords.go?at=default&fileviewer=file-view-default
const (
numBitsPerComponent = 12
modulo = 1 << numBitsPerComponent
Expand Down Expand Up @@ -74,3 +74,8 @@ func (repo *sqliteBlockRepository) Delete(x, y, z int) error {
_, err := repo.db.Exec("delete from blocks where pos=$1", pos)
return err
}

func (repo *sqliteBlockRepository) Vacuum() error {
_, err := repo.db.Exec("vacuum")
return err
}
2 changes: 2 additions & 0 deletions block/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ func testBlocksRepository(t *testing.T, block_repo block.BlockRepository) {
assert.NoError(t, err)
assert.Nil(t, b)

// vacuum
assert.NoError(t, block_repo.Vacuum())
}
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ services:
postgres:
image: postgres:15.1
restart: always
ports:
- "5432:5432"
environment:
POSTGRES_PASSWORD: enter
volumes:
Expand Down

0 comments on commit 1c55846

Please sign in to comment.