Merge lp:~ted/indicator-appmenu/db-now-with-indexes into lp:indicator-appmenu/0.4

Proposed by Ted Gould
Status: Merged
Approved by: Mikkel Kamstrup Erlandsen
Approved revision: 174
Merged at revision: 139
Proposed branch: lp:~ted/indicator-appmenu/db-now-with-indexes
Merge into: lp:indicator-appmenu/0.4
Prerequisite: lp:~ted/indicator-appmenu/hud
Diff against target: 190 lines (+33/-7)
11 files modified
.bzrignore (+1/-0)
src/Makefile.am (+16/-1)
src/create-db.h (+4/-0)
src/create-db.sql (+2/-1)
src/hud-verify-app-info.c (+2/-1)
src/usage-tracker.c (+2/-1)
tests/Makefile.am (+2/-3)
tests/test-usage-db-ancient.c (+1/-0)
tests/test-usage-db-old.c (+1/-0)
tests/test-usage-db-simple.c (+1/-0)
tests/test-usage-db-testapp.c (+1/-0)
To merge this branch: bzr merge lp:~ted/indicator-appmenu/db-now-with-indexes
Reviewer Review Type Date Requested Status
Mikkel Kamstrup Erlandsen (community) Approve
Review via email: mp+90204@code.launchpad.net

Description of the change

Adding an index to the creation of the db. But, also refactoring so there's one place to put this.

To post a comment you must log in.
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

72 create table usage (application text, entry text, timestamp datetime);
73 +create index if not exists application_index on usage (application);

You might want to also 'create table if not exists ...' for the main table.

143 === modified file 'tests/test-usage-db-ancient.c'
144 --- tests/test-usage-db-ancient.c 2012-01-25 20:43:26 +0000
145 +++ tests/test-usage-db-ancient.c 2012-01-25 20:43:27 +0000
146 @@ -27,6 +27,7 @@
147 #include "usage-tracker.h"
148 #include "usage-tracker.c"
149 #include "utils.c"
150 +#include "create-db.c"

Is it not #include "create-db.h". That is s/.c/.h/ ? Same for all test files.

Revision history for this message
Ted Gould (ted) wrote :

On Thu, 2012-01-26 at 12:59 +0000, Mikkel Kamstrup Erlandsen wrote:
> 72 create table usage (application text, entry text, timestamp datetime);
> 73 +create index if not exists application_index on usage (application);
>
> You might want to also 'create table if not exists ...' for the main table.

Fixed r174

> 143 === modified file 'tests/test-usage-db-ancient.c'
> 144 --- tests/test-usage-db-ancient.c 2012-01-25 20:43:26 +0000
> 145 +++ tests/test-usage-db-ancient.c 2012-01-25 20:43:27 +0000
> 146 @@ -27,6 +27,7 @@
> 147 #include "usage-tracker.h"
> 148 #include "usage-tracker.c"
> 149 #include "utils.c"
> 150 +#include "create-db.c"
>
> Is it not #include "create-db.h". That is s/.c/.h/ ? Same for all test files.

autotools :-( I couldn't get all the deps right, and I didn't want to
build a library out of the objects to get included... and it *was* only
one file. But it's getting out of hand now. Either need to switch to a
single high level Makefile.am or build libs.

174. By Ted Gould

Only build the table if it doesn't exist.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

> autotools :-( I couldn't get all the deps right, and I didn't want to
> build a library out of the objects to get included... and it *was* only
> one file. But it's getting out of hand now. Either need to switch to a
> single high level Makefile.am or build libs.

Ah, now I get it. At first I thought it was typo. I looked for the generation in Makefile.am and somehow missed it, but I see it now :-)

But looking good on the sql now. Great stuff!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-01-26 16:04:27 +0000
3+++ .bzrignore 2012-01-26 16:04:27 +0000
4@@ -168,3 +168,4 @@
5 tests/test_usage_db_simple-test-usage-db-simple.gcno
6 tests/test_usage_db_testapp-test-usage-db-testapp.gcda
7 tests/test_usage_db_testapp-test-usage-db-testapp.gcno
8+create-db.c
9
10=== modified file 'src/Makefile.am'
11--- src/Makefile.am 2012-01-26 16:04:27 +0000
12+++ src/Makefile.am 2012-01-26 16:04:27 +0000
13@@ -81,6 +81,8 @@
14 ####################
15
16 hud_service_SOURCES = \
17+ create-db.h \
18+ create-db.c \
19 dbusmenu-collector.h \
20 dbusmenu-collector.c \
21 distance.h \
22@@ -112,6 +114,16 @@
23 hud_service_LDFLAGS = \
24 $(HUD_LIBS)
25
26+create-db.c: create-db.sql
27+ echo "#include \"create-db.h\"" > $@
28+ echo -n "const gchar * create_db = \"" >> $@
29+ cat $< | xargs printf "%s " >> $@
30+ echo -n "\";" >> $@
31+
32+CLEANFILES += \
33+ create-db.c
34+
35+
36 ####################
37 # HUD CLI
38 ####################
39@@ -161,6 +173,8 @@
40 #######################
41
42 hud_verify_app_info_SOURCES = \
43+ create-db.h \
44+ create-db.c \
45 load-app-info.h \
46 load-app-info.c \
47 hud-verify-app-info.c
48@@ -177,7 +191,8 @@
49 ####################
50
51 EXTRA_DIST += \
52- hud.xml
53+ hud.xml \
54+ create-db.sql
55
56 BUILT_SOURCES += \
57 hud.interface.c \
58
59=== added file 'src/create-db.h'
60--- src/create-db.h 1970-01-01 00:00:00 +0000
61+++ src/create-db.h 2012-01-26 16:04:27 +0000
62@@ -0,0 +1,4 @@
63+
64+#include <glib.h>
65+
66+extern const gchar * create_db;
67
68=== renamed file 'tests/test-create-db.sql' => 'src/create-db.sql'
69--- tests/test-create-db.sql 2012-01-26 16:04:27 +0000
70+++ src/create-db.sql 2012-01-26 16:04:27 +0000
71@@ -1,1 +1,2 @@
72-create table usage (application text, entry text, timestamp datetime);
73+create table if not exists usage (application text, entry text, timestamp datetime);
74+create index if not exists application_index on usage (application);
75
76=== modified file 'src/hud-verify-app-info.c'
77--- src/hud-verify-app-info.c 2012-01-26 16:04:27 +0000
78+++ src/hud-verify-app-info.c 2012-01-26 16:04:27 +0000
79@@ -24,6 +24,7 @@
80 #include <glib/gstdio.h>
81 #include <glib-object.h>
82 #include "load-app-info.h"
83+#include "create-db.h"
84
85 static void
86 build_db (sqlite3 * db)
87@@ -32,7 +33,7 @@
88 int exec_status = SQLITE_OK;
89 gchar * failstring = NULL;
90 exec_status = sqlite3_exec(db,
91- "create table usage (application text, entry text, timestamp datetime);",
92+ create_db,
93 NULL, NULL, &failstring);
94 if (exec_status != SQLITE_OK) {
95 g_warning("Unable to create table: %s", failstring);
96
97=== modified file 'src/usage-tracker.c'
98--- src/usage-tracker.c 2012-01-26 16:04:27 +0000
99+++ src/usage-tracker.c 2012-01-26 16:04:27 +0000
100@@ -31,6 +31,7 @@
101 #include "usage-tracker.h"
102 #include "load-app-info.h"
103 #include "utils.h"
104+#include "create-db.h"
105
106 struct _UsageTrackerPrivate {
107 gchar * cachefile;
108@@ -353,7 +354,7 @@
109 int exec_status = SQLITE_OK;
110 gchar * failstring = NULL;
111 exec_status = sqlite3_exec(self->priv->db,
112- "create table usage (application text, entry text, timestamp datetime);",
113+ create_db,
114 NULL, NULL, &failstring);
115 if (exec_status != SQLITE_OK) {
116 g_warning("Unable to create table: %s", failstring);
117
118=== modified file 'tests/Makefile.am'
119--- tests/Makefile.am 2012-01-26 16:04:27 +0000
120+++ tests/Makefile.am 2012-01-26 16:04:27 +0000
121@@ -181,11 +181,11 @@
122
123 USAGE_TESTAPP_XML_REPORT = test-usage-db-testapp.xml
124
125-test-usage-db-testapp-test: test-usage-db-testapp good-app-info/testapp.desktop.hud-app-info good-app-info/testapp100.desktop.hud-app-info test-create-db.sql Makefile.am
126+test-usage-db-testapp-test: test-usage-db-testapp good-app-info/testapp.desktop.hud-app-info good-app-info/testapp100.desktop.hud-app-info $(top_srcdir)/src/create-db.sql Makefile.am
127 @echo "#!/bin/bash -e" > $@
128 @echo cd \`mktemp -d $(abs_builddir)/test-usage-db-testapp.dir.XXXXXX\` >> $@
129 @echo mkdir -p indicator-appmenu >> $@
130- @echo cat $(abs_srcdir)/test-create-db.sql \| sqlite3 indicator-appmenu/hud-usage-log.sqlite >> $@
131+ @echo cat $(abs_top_srcdir)/src/create-db.sql \| sqlite3 indicator-appmenu/hud-usage-log.sqlite >> $@
132 @echo export HUD_CACHE_DIR=\`pwd\` >> $@
133 @echo export HUD_APP_INFO_DIR=$(abs_srcdir)/good-app-info >> $@
134 @echo export GSETTINGS_BACKEND=memory >> $@
135@@ -209,7 +209,6 @@
136 $(HUD_LIBS)
137
138 EXTRA_DIST += \
139- test-create-db.sql \
140 good-app-info/testapp100.desktop.hud-app-info \
141 good-app-info/testapp.desktop.hud-app-info
142
143
144=== modified file 'tests/test-usage-db-ancient.c'
145--- tests/test-usage-db-ancient.c 2012-01-26 16:04:27 +0000
146+++ tests/test-usage-db-ancient.c 2012-01-26 16:04:27 +0000
147@@ -27,6 +27,7 @@
148 #include "usage-tracker.h"
149 #include "usage-tracker.c"
150 #include "utils.c"
151+#include "create-db.c"
152
153 gint
154 main (gint argc, gchar * argv[])
155
156=== modified file 'tests/test-usage-db-old.c'
157--- tests/test-usage-db-old.c 2012-01-26 16:04:27 +0000
158+++ tests/test-usage-db-old.c 2012-01-26 16:04:27 +0000
159@@ -27,6 +27,7 @@
160 #include "usage-tracker.h"
161 #include "usage-tracker.c"
162 #include "utils.c"
163+#include "create-db.c"
164
165 /* Ensure the base object works */
166 static void
167
168=== modified file 'tests/test-usage-db-simple.c'
169--- tests/test-usage-db-simple.c 2012-01-26 16:04:27 +0000
170+++ tests/test-usage-db-simple.c 2012-01-26 16:04:27 +0000
171@@ -27,6 +27,7 @@
172 #include "usage-tracker.h"
173 #include "usage-tracker.c"
174 #include "utils.c"
175+#include "create-db.c"
176
177 /* Ensure the base object works */
178 static void
179
180=== modified file 'tests/test-usage-db-testapp.c'
181--- tests/test-usage-db-testapp.c 2012-01-26 16:04:27 +0000
182+++ tests/test-usage-db-testapp.c 2012-01-26 16:04:27 +0000
183@@ -29,6 +29,7 @@
184 #include "usage-tracker.c"
185 #include "shared-values.h"
186 #include "utils.c"
187+#include "create-db.c"
188
189 static void
190 test_usage_testapp (void)

Subscribers

People subscribed via source and target branches