<pre style='margin:0'>
Joshua Root (jmroot) pushed a commit to branch master
in repository macports-base.
</pre>
<p><a href="https://github.com/macports/macports-base/commit/29f78890df4748ded2a13e3bae96a71a225f2cb2">https://github.com/macports/macports-base/commit/29f78890df4748ded2a13e3bae96a71a225f2cb2</a></p>
<pre style="white-space: pre; background: #F8F8F8">The following commit(s) were added to refs/heads/master by this push:
<span style='display:block; white-space:pre;color:#404040;'> new 29f78890d Run 'PRAGMA optimize' when closing registry
</span>29f78890d is described below
<span style='display:block; white-space:pre;color:#808000;'>commit 29f78890df4748ded2a13e3bae96a71a225f2cb2
</span>Author: Joshua Root <jmr@macports.org>
AuthorDate: Tue Sep 3 14:13:32 2024 +1000
<span style='display:block; white-space:pre;color:#404040;'> Run 'PRAGMA optimize' when closing registry
</span>---
src/cregistry/registry.c | 33 +++++++++++++++++++++++++++++++++
src/cregistry/registry.h | 1 +
src/registry2.0/registry.c | 13 +++++++++++++
3 files changed, 47 insertions(+)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/registry.c b/src/cregistry/registry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 2b24642f4..ac3d2e16f 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -595,6 +595,39 @@ int reg_checkpoint(reg_registry* reg, reg_error* errPtr) {
</span> return 1;
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+/**
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Runs PRAGMA optimize on the given db if supported.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [in] reg the registry to optimize
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @return true if success; false if failure
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_optimize(reg_registry* reg, reg_error* errPtr)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+{
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#if SQLITE_VERSION_NUMBER >= 3018000
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (sqlite3_prepare_v2(reg->db, "PRAGMA optimize", -1, &stmt, NULL) == SQLITE_OK) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = sqlite3_reset(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (r == SQLITE_OK) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!result) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_sqlite_error(reg->db, errPtr, NULL);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#else
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+#endif
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> /**
* Functions for access to the metadata table
*/
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/registry.h b/src/cregistry/registry.h
</span><span style='display:block; white-space:pre;color:#808080;'>index acd3bd66b..2440190ad 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/registry.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/registry.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -97,6 +97,7 @@ int reg_rollback(reg_registry* reg, reg_error* errPtr);
</span>
int reg_vacuum(char* db_path);
int reg_checkpoint(reg_registry* reg, reg_error* errPtr);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_optimize(reg_registry* reg, reg_error* errPtr);
</span>
int reg_get_metadata(reg_registry* reg, const char* key, char** value, reg_error* errPtr);
int reg_set_metadata(reg_registry* reg, const char* key, const char* value, reg_error* errPtr);
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/registry2.0/registry.c b/src/registry2.0/registry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 47c304ea8..64a0b5ce7 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/registry2.0/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/registry2.0/registry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -142,10 +142,18 @@ int registry_tcl_detach(Tcl_Interp* interp, reg_registry* reg,
</span> static void delete_reg(ClientData reg, Tcl_Interp* interp) {
reg_error error;
if (((reg_registry*)reg)->status & reg_attached) {
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (reg_optimize((reg_registry*)reg, &error) == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(stderr, "%s\n", error.description);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error_destruct(&error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span> if (Tcl_GetAssocData(interp, "registry::needs_vacuum", NULL) != NULL) {
reg_vacuum(Tcl_GetAssocData(interp, "registry::db_path", NULL));
Tcl_DeleteAssocData(interp, "registry::needs_vacuum");
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (reg_checkpoint((reg_registry*)reg, &error) == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(stderr, "%s\n", error.description);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error_destruct(&error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span> if (!registry_tcl_detach(interp, (reg_registry*)reg, &error)) {
fprintf(stderr, "%s", error.description);
reg_error_destruct(&error);
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -236,6 +244,10 @@ static int registry_close(ClientData clientData UNUSED, Tcl_Interp* interp,
</span> return TCL_ERROR;
} else {
reg_error error;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (reg_optimize(reg, &error) == 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ fprintf(stderr, "%s\n", error.description);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error_destruct(&error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span> if (Tcl_GetAssocData(interp, "registry::needs_vacuum", NULL) != NULL) {
reg_vacuum(Tcl_GetAssocData(interp, "registry::db_path", NULL));
Tcl_DeleteAssocData(interp, "registry::needs_vacuum");
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -243,6 +255,7 @@ static int registry_close(ClientData clientData UNUSED, Tcl_Interp* interp,
</span> /* Not really anything we can do if this fails. */
if (reg_checkpoint(reg, &error) == 0) {
fprintf(stderr, "%s\n", error.description);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error_destruct(&error);
</span> }
if (registry_tcl_detach(interp, reg, &error)) {
return TCL_OK;
</pre><pre style='margin:0'>
</pre>