[aur-dev] [PATCH 1/3] aurblup: blacklist processing query changes
* Do all list building and freeing outside of the transaction to keep it as short as possible. * Remove ability to blacklist without transactions as we now only support InnoDB/transactional engines with proper relations. * No need to turn autocommit off; BEGIN TRANSACTION operates regardless of this setting. Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/aurblup.c | 23 +++++------------------ scripts/aurblup/config.h.proto | 3 --- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/scripts/aurblup/aurblup.c b/scripts/aurblup/aurblup.c index fea7ffc..1f7aefc 100644 --- a/scripts/aurblup/aurblup.c +++ b/scripts/aurblup/aurblup.c @@ -122,19 +122,11 @@ blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new) { alpm_list_t *pkgs_add, *pkgs_rem, *p; -#if MYSQL_USE_TRANSACTIONS - if (mysql_autocommit(c, 0)) - mysql_die("failed to turn MySQL autocommit off: %s\n"); + pkgs_add = alpm_list_diff(pkgs_new, pkgs_cur, (alpm_list_fn_cmp)strcmp); + pkgs_rem = alpm_list_diff(pkgs_cur, pkgs_new, (alpm_list_fn_cmp)strcmp); if (mysql_query(c, "START TRANSACTION;")) mysql_die("failed to start MySQL transaction: %s\n"); -#else - if (mysql_query(c, "LOCK TABLES PackageBlacklist WRITE;")) - mysql_die("failed to lock MySQL table: %s\n"); -#endif - - pkgs_add = alpm_list_diff(pkgs_new, pkgs_cur, (alpm_list_fn_cmp)strcmp); - pkgs_rem = alpm_list_diff(pkgs_cur, pkgs_new, (alpm_list_fn_cmp)strcmp); for (p = pkgs_add; p; p = alpm_list_next(p)) blacklist_add(alpm_list_getdata(p)); @@ -142,16 +134,11 @@ blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new) for (p = pkgs_rem; p; p = alpm_list_next(p)) blacklist_remove(alpm_list_getdata(p)); - alpm_list_free(pkgs_add); - alpm_list_free(pkgs_rem); - -#if MYSQL_USE_TRANSACTIONS if (mysql_query(c, "COMMIT;")) mysql_die("failed to commit MySQL transaction: %s\n"); -#else - if (mysql_query(c, "UNLOCK TABLES;")) - mysql_die("failed to unlock MySQL tables: %s\n"); -#endif + + alpm_list_free(pkgs_add); + alpm_list_free(pkgs_rem); } alpm_list_t * diff --git a/scripts/aurblup/config.h.proto b/scripts/aurblup/config.h.proto index fc1a87b..daf1744 100644 --- a/scripts/aurblup/config.h.proto +++ b/scripts/aurblup/config.h.proto @@ -6,9 +6,6 @@ #define CONFIG_KEY_PASSWD "AUR_db_pass" #define CONFIG_KEY_DB "AUR_db_name" -/* unset this to use "LOCK TABLE" instead of transactions */ -#define MYSQL_USE_TRANSACTIONS 1 - /* libalpm options */ #define ALPM_DBPATH "/var/lib/aurblup/" #define ALPM_MIRROR "ftp://mirrors.kernel.org/archlinux/%s/os/i686" -- 1.7.5.2
These don't need visibility outside of this compilation unit. This also allows a C compiler to inline and optimize as it sees fit. Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/aurblup.c | 46 ++++++++++++++++++++++---------------------- 1 files changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/aurblup/aurblup.c b/scripts/aurblup/aurblup.c index 1f7aefc..6a67d68 100644 --- a/scripts/aurblup/aurblup.c +++ b/scripts/aurblup/aurblup.c @@ -14,17 +14,17 @@ #define alpm_die(...) die(__VA_ARGS__, alpm_strerrorlast()); #define mysql_die(...) die(__VA_ARGS__, mysql_error(c)); -void die(const char *, ...); -alpm_list_t *pkglist_append(alpm_list_t *, const char *); -alpm_list_t *blacklist_get_pkglist(); -void blacklist_add(const char *); -void blacklist_remove(const char *); -void blacklist_sync(alpm_list_t *, alpm_list_t *); -alpm_list_t *dblist_get_pkglist(alpm_list_t *); -alpm_list_t *dblist_create(void); -void read_config(const char *); -void init(void); -void cleanup(void); +static void die(const char *, ...); +static alpm_list_t *pkglist_append(alpm_list_t *, const char *); +static alpm_list_t *blacklist_get_pkglist(); +static void blacklist_add(const char *); +static void blacklist_remove(const char *); +static void blacklist_sync(alpm_list_t *, alpm_list_t *); +static alpm_list_t *dblist_get_pkglist(alpm_list_t *); +static alpm_list_t *dblist_create(void); +static void read_config(const char *); +static void init(void); +static void cleanup(void); static char *mysql_host = NULL; static char *mysql_socket = NULL; @@ -32,9 +32,9 @@ static char *mysql_user = NULL; static char *mysql_passwd = NULL; static char *mysql_db = NULL; -MYSQL *c; +static MYSQL *c; -void +static void die(const char *format, ...) { va_list arg; @@ -48,7 +48,7 @@ die(const char *format, ...) exit(1); } -alpm_list_t * +static alpm_list_t * pkglist_append(alpm_list_t *pkglist, const char *pkgname) { int len = strcspn(pkgname, "<=>"); @@ -67,7 +67,7 @@ pkglist_append(alpm_list_t *pkglist, const char *pkgname) return pkglist; } -alpm_list_t * +static alpm_list_t * blacklist_get_pkglist() { MYSQL_RES *res; @@ -88,7 +88,7 @@ blacklist_get_pkglist() return pkglist; } -void +static void blacklist_add(const char *name) { char *esc = malloc(strlen(name) * 2 + 1); @@ -103,7 +103,7 @@ blacklist_add(const char *name) mysql_die("failed to query MySQL database (\"%s\"): %s\n", query); } -void +static void blacklist_remove(const char *name) { char *esc = malloc(strlen(name) * 2 + 1); @@ -117,7 +117,7 @@ blacklist_remove(const char *name) mysql_die("failed to query MySQL database (\"%s\"): %s\n", query); } -void +static void blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new) { alpm_list_t *pkgs_add, *pkgs_rem, *p; @@ -141,7 +141,7 @@ blacklist_sync(alpm_list_t *pkgs_cur, alpm_list_t *pkgs_new) alpm_list_free(pkgs_rem); } -alpm_list_t * +static alpm_list_t * dblist_get_pkglist(alpm_list_t *dblist) { alpm_list_t *d, *p, *q; @@ -173,7 +173,7 @@ dblist_get_pkglist(alpm_list_t *dblist) return pkglist; } -alpm_list_t * +static alpm_list_t * dblist_create(void) { alpm_list_t *d; @@ -201,7 +201,7 @@ dblist_create(void) return dblist; } -void +static void read_config(const char *fn) { FILE *fp; @@ -258,7 +258,7 @@ read_config(const char *fn) die("MySQL database setting not found in AUR config file\n"); } -void +static void init(void) { if (mysql_library_init(0, NULL, NULL)) @@ -277,7 +277,7 @@ init(void) alpm_die("failed to set ALPM database path: %s\n"); } -void +static void cleanup(void) { if (mysql_host) free(mysql_host); -- 1.7.5.2
We don't need to add rules for implicit .c -> .o conversions. Also add -O2 to the CFLAGS as gcc doesn't print many warnings unless at least some level of optimization is used. Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/Makefile | 4 ---- scripts/aurblup/config.mk | 2 +- 2 files changed, 1 insertions(+), 5 deletions(-) diff --git a/scripts/aurblup/Makefile b/scripts/aurblup/Makefile index 67fcac1..2d57470 100644 --- a/scripts/aurblup/Makefile +++ b/scripts/aurblup/Makefile @@ -5,16 +5,12 @@ OBJ = ${SRC:.c=.o} all: aurblup -.c.o: - ${CC} -c ${CFLAGS} $< - config.h: cp config.h.proto config.h ${OBJ}: config.h aurblup: ${OBJ} - ${CC} -o $@ ${OBJ} ${LDFLAGS} install: aurblup install -Dm0755 aurblup "${DESTDIR}${PREFIX}/bin/aurblup" diff --git a/scripts/aurblup/config.mk b/scripts/aurblup/config.mk index 9545f2c..f8e12a8 100644 --- a/scripts/aurblup/config.mk +++ b/scripts/aurblup/config.mk @@ -1,6 +1,6 @@ PREFIX = /usr/local -CFLAGS = -g -std=c99 -pedantic -Wall -I/usr/include/mysql +CFLAGS = -g -O2 -std=c99 -pedantic -Wall -I/usr/include/mysql LDFLAGS = -g -lalpm -lmysqlclient CC = cc -- 1.7.5.2
On Mon, Jun 27, 2011 at 05:31:31PM -0500, Dan McGee wrote:
These don't need visibility outside of this compilation unit. This also allows a C compiler to inline and optimize as it sees fit.
Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/aurblup.c | 46 ++++++++++++++++++++++---------------------- 1 files changed, 23 insertions(+), 23 deletions(-)
Holy sh**... Yeah, just pushed those! On Mon, Jun 27, 2011 at 05:31:32PM -0500, Dan McGee wrote:
We don't need to add rules for implicit .c -> .o conversions. Also add -O2 to the CFLAGS as gcc doesn't print many warnings unless at least some level of optimization is used.
Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/Makefile | 4 ---- scripts/aurblup/config.mk | 2 +- 2 files changed, 1 insertions(+), 5 deletions(-)
... and this one as well. Thanks!
On Mon, Jun 27, 2011 at 05:31:30PM -0500, Dan McGee wrote:
* Do all list building and freeing outside of the transaction to keep it as short as possible. * Remove ability to blacklist without transactions as we now only support InnoDB/transactional engines with proper relations. * No need to turn autocommit off; BEGIN TRANSACTION operates regardless of this setting.
Signed-off-by: Dan McGee <dan@archlinux.org> --- scripts/aurblup/aurblup.c | 23 +++++------------------ scripts/aurblup/config.h.proto | 3 --- 2 files changed, 5 insertions(+), 21 deletions(-)
Pushed this one, thanks!
participants (2)
-
Dan McGee
-
Lukas Fleischer