Skip to content

Commit 3aa2827

Browse files
authored
Merge 09b2b62 into eaaac5c
2 parents eaaac5c + 09b2b62 commit 3aa2827

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

hyperpage.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,14 @@ static sqlite3 *get_handle(std::unique_ptr<void, std::function<void(void *)>> &h
3333
return static_cast<sqlite3 *>(handle.get());
3434
}
3535

36+
template <bool IsWriter>
3637
static void close_handle(void *handle)
3738
{
3839
sqlite3 *db = static_cast<sqlite3 *>(handle);
40+
if (IsWriter)
41+
{
42+
sqlite3_exec(db, "VACUUM;", nullptr, nullptr, nullptr);
43+
}
3944
sqlite3_close(db);
4045
}
4146

@@ -100,7 +105,7 @@ class stored_page : public hyperpage::page
100105
size_t _length;
101106
};
102107

103-
hyperpage::reader::reader(const std::string &db_path) : _handle(nullptr, close_handle)
108+
hyperpage::reader::reader(const std::string &db_path) : _handle(nullptr, close_handle<false>)
104109
{
105110
sqlite3 *db = nullptr;
106111
if (!sqlite_call(SQLITE_OK, sqlite3_open, db_path.c_str(), &db))
@@ -121,7 +126,7 @@ std::unique_ptr<hyperpage::page> hyperpage::reader::load(const std::string &page
121126
return result;
122127
}
123128

124-
hyperpage::writer::writer(const std::string &db_path) : _handle(nullptr, close_handle)
129+
hyperpage::writer::writer(const std::string &db_path) : _handle(nullptr, close_handle<true>)
125130
{
126131
sqlite3 *db = nullptr;
127132
if (!sqlite_call(SQLITE_OK, sqlite3_open, db_path.c_str(), &db))

hyperpage.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ namespace hyperpage
111111
* @param db_path The path to the hyperpage database file.
112112
*/
113113
writer(const std::string &db_path);
114+
114115
/**
115116
* @brief Stores a page in the hyperpage database.
116117
*

0 commit comments

Comments
 (0)