Skip to content

Commit 23f585c

Browse files
committed
Unify set SQLite PRAGMAs.
1 parent 626caad commit 23f585c

File tree

4 files changed

+6
-19
lines changed

4 files changed

+6
-19
lines changed

sqlite/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ endif()
3333

3434
target_compile_definitions(tdsqlite PRIVATE
3535
-DSQLITE_DEFAULT_MEMSTATUS=0
36+
-DSQLITE_DEFAULT_SYNCHRONOUS=1
37+
-DSQLITE_DEFAULT_RECURSIVE_TRIGGERS=1
38+
-DSQLITE_TEMP_STORE=2
3639
-DSQLITE_OMIT_LOAD_EXTENSION
3740
-DSQLITE_OMIT_DECLTYPE
3841
-DSQLITE_OMIT_PROGRESS_CALLBACK

td/telegram/LanguagePackManager.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,6 @@ bool LanguagePackManager::is_custom_language_code(Slice language_code) {
125125

126126
static Result<SqliteDb> open_database(const string &path) {
127127
TRY_RESULT(database, SqliteDb::open_with_key(path, true, DbKey::empty()));
128-
TRY_STATUS(database.exec("PRAGMA synchronous=NORMAL"));
129-
TRY_STATUS(database.exec("PRAGMA temp_store=MEMORY"));
130-
TRY_STATUS(database.exec("PRAGMA encoding=\"UTF-8\""));
131128
TRY_STATUS(database.exec("PRAGMA journal_mode=WAL"));
132129
return std::move(database);
133130
}

td/telegram/TdDb.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,6 @@ Status init_binlog(Binlog &binlog, string path, BinlogKeyValue<Binlog> &binlog_p
142142
return Status::OK();
143143
}
144144

145-
Status init_db(SqliteDb &db) {
146-
TRY_STATUS(db.exec("PRAGMA encoding=\"UTF-8\""));
147-
TRY_STATUS(db.exec("PRAGMA journal_mode=WAL"));
148-
149-
TRY_STATUS(db.exec("PRAGMA synchronous=NORMAL"));
150-
TRY_STATUS(db.exec("PRAGMA temp_store=MEMORY"));
151-
TRY_STATUS(db.exec("PRAGMA secure_delete=1"));
152-
153-
return Status::OK();
154-
}
155-
156145
} // namespace
157146

158147
std::shared_ptr<FileDbInterface> TdDb::get_file_db_shared() {
@@ -310,8 +299,8 @@ Status TdDb::init_sqlite(int32 scheduler_id, const TdParameters &parameters, DbK
310299
sql_connection_ = std::make_shared<SqliteConnectionSafe>(sql_database_path, key, db_instance.get_cipher_version());
311300
sql_connection_->set(std::move(db_instance));
312301
auto &db = sql_connection_->get();
313-
314-
TRY_STATUS(init_db(db));
302+
TRY_STATUS(db.exec("PRAGMA journal_mode=WAL"));
303+
TRY_STATUS(db.exec("PRAGMA secure_delete=1"));
315304

316305
// Init databases
317306
// Do initialization once and before everything else to avoid "database is locked" error.

tddb/td/db/SqliteConnectionSafe.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ SqliteConnectionSafe::SqliteConnectionSafe(string path, DbKey key, optional<int3
2121
LOG(FATAL) << "Can't open database: " << r_db.error().message();
2222
}
2323
auto db = r_db.move_as_ok();
24-
db.exec("PRAGMA synchronous=NORMAL").ensure();
25-
db.exec("PRAGMA temp_store=MEMORY").ensure();
24+
db.exec("PRAGMA journal_mode=WAL").ensure();
2625
db.exec("PRAGMA secure_delete=1").ensure();
27-
db.exec("PRAGMA recursive_triggers=1").ensure();
2826
return db;
2927
}) {
3028
}

0 commit comments

Comments
 (0)