toolbox

Check-in [348331d2a4]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:rss: avoid open db in parent process while refresshing feeds in child workers
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:348331d2a44c87b2a1badaceea6df6466c06b875989563f4d1c58179021cd7f3
User & Date: jef 2019-04-11 10:45:50
Context
2019-04-14
15:27
radio: fix broken streams check-in: 0ec0037646 user: jef tags: trunk
2019-04-11
10:45
rss: avoid open db in parent process while refresshing feeds in child workers check-in: 348331d2a4 user: jef tags: trunk
2019-04-01
20:14
radio: remove duplicate radios check-in: 750ac9bfab user: jef tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/rss/feeds.c.

132
133
134
135
136
137
138

139
140
141
142
143
144
145
146
147
148
149
150


151
152
153
154
155
156
157
158
159

160
161
162
163
164
165

166
167
168
169
170
171
172
173
174
175
176
177
178

179
180
181
182
183
184
185
...
194
195
196
197
198
199
200

201
202
203
204
205
206
207
...
218
219
220
221
222
223
224

225
226
227
228
229
230
231

232
233
234
235
236
237
238
	struct feed *feed;
	int rc;

	feed = feed_parse(feedlink);
	if (feed == NULL)
		return;


	stmt = db_prepare("INSERT INTO feeds (title, description, link, feedlink)"
				" VALUES (?, ?, ?, ?)");
	sqlite3_bind_text(stmt, 1, feed->title, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 2, feed->description, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 3, feed->link, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 4, feed->feedlink, -1, SQLITE_STATIC);
	rc = sqlite3_step(stmt);
	if (rc != SQLITE_DONE)
		die("unable to add feed: %s", db_error());
	sqlite3_finalize(stmt);

	feed_refresh(feed);


	feed_free(feed);
}

void
feed_del(const char *feedlink)
{
	sqlite3_stmt *stmt;
	int rc;


	stmt = db_prepare("DELETE FROM feeds WHERE feedlink = ?");
	sqlite3_bind_text(stmt, 1, feedlink, -1, SQLITE_STATIC);
	rc = sqlite3_step(stmt);
	if (rc != SQLITE_DONE)
		die("unable to delete feed: %s", db_error());
	sqlite3_finalize(stmt);

}

void
feeds_display()
{
	sqlite3_stmt *res;
	char *title, *desc, *link, *feedlink, *json;
	cJSON *feeds, *feed, *jstitle, *jsdesc, *jslink, *jsfeedlink;
	int step;

	feeds = cJSON_CreateArray();
	if (feeds == NULL)
		goto jsonerr;

	res = db_prepare("SELECT title, description, link, feedlink FROM feeds;");
	while ((step = sqlite3_step(res)) == SQLITE_ROW) {
		title = (char *) sqlite3_column_text(res, 0);
		desc = (char *) sqlite3_column_text(res, 1);
		link = (char *) sqlite3_column_text(res, 2);
		feedlink = (char *) sqlite3_column_text(res, 3);

................................................................................
		cJSON_AddItemToArray(feeds, feed);
		cJSON_AddItemToObject(feed, "title", jstitle);
		cJSON_AddItemToObject(feed, "description", jsdesc);
		cJSON_AddItemToObject(feed, "link", jslink);
		cJSON_AddItemToObject(feed, "feedlink", jsfeedlink);
	}
	sqlite3_finalize(res);


	json = cJSON_Print(feeds);
	if (json == NULL)
		goto jsonerr;
	puts(json);
	cJSON_free(json);
	cJSON_Delete(feeds);
................................................................................
	struct feedlink *feedlink;
	sqlite3_stmt *res;
	int step;

	feedlinks = xcalloc(1, sizeof(struct feedlinks));
	TAILQ_INIT(feedlinks);


	res = db_prepare("SELECT feedlink FROM feeds;");
	while ((step = sqlite3_step(res)) == SQLITE_ROW) {
		feedlink = xcalloc(1, sizeof(struct feedlink));
		feedlink->url = xstrdup((char *) sqlite3_column_text(res, 0));
		TAILQ_INSERT_TAIL(feedlinks, feedlink, next);
	}
	sqlite3_finalize(res);


	return feedlinks;
}

void
feeds_refresh()
{







>










<

>
>









>






>













>







 







>







 







>







>







132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
...
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
	struct feed *feed;
	int rc;

	feed = feed_parse(feedlink);
	if (feed == NULL)
		return;

	db_open();
	stmt = db_prepare("INSERT INTO feeds (title, description, link, feedlink)"
				" VALUES (?, ?, ?, ?)");
	sqlite3_bind_text(stmt, 1, feed->title, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 2, feed->description, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 3, feed->link, -1, SQLITE_STATIC);
	sqlite3_bind_text(stmt, 4, feed->feedlink, -1, SQLITE_STATIC);
	rc = sqlite3_step(stmt);
	if (rc != SQLITE_DONE)
		die("unable to add feed: %s", db_error());
	sqlite3_finalize(stmt);

	feed_refresh(feed);
	db_close();

	feed_free(feed);
}

void
feed_del(const char *feedlink)
{
	sqlite3_stmt *stmt;
	int rc;

	db_open();
	stmt = db_prepare("DELETE FROM feeds WHERE feedlink = ?");
	sqlite3_bind_text(stmt, 1, feedlink, -1, SQLITE_STATIC);
	rc = sqlite3_step(stmt);
	if (rc != SQLITE_DONE)
		die("unable to delete feed: %s", db_error());
	sqlite3_finalize(stmt);
	db_close();
}

void
feeds_display()
{
	sqlite3_stmt *res;
	char *title, *desc, *link, *feedlink, *json;
	cJSON *feeds, *feed, *jstitle, *jsdesc, *jslink, *jsfeedlink;
	int step;

	feeds = cJSON_CreateArray();
	if (feeds == NULL)
		goto jsonerr;
	db_open();
	res = db_prepare("SELECT title, description, link, feedlink FROM feeds;");
	while ((step = sqlite3_step(res)) == SQLITE_ROW) {
		title = (char *) sqlite3_column_text(res, 0);
		desc = (char *) sqlite3_column_text(res, 1);
		link = (char *) sqlite3_column_text(res, 2);
		feedlink = (char *) sqlite3_column_text(res, 3);

................................................................................
		cJSON_AddItemToArray(feeds, feed);
		cJSON_AddItemToObject(feed, "title", jstitle);
		cJSON_AddItemToObject(feed, "description", jsdesc);
		cJSON_AddItemToObject(feed, "link", jslink);
		cJSON_AddItemToObject(feed, "feedlink", jsfeedlink);
	}
	sqlite3_finalize(res);
	db_close();

	json = cJSON_Print(feeds);
	if (json == NULL)
		goto jsonerr;
	puts(json);
	cJSON_free(json);
	cJSON_Delete(feeds);
................................................................................
	struct feedlink *feedlink;
	sqlite3_stmt *res;
	int step;

	feedlinks = xcalloc(1, sizeof(struct feedlinks));
	TAILQ_INIT(feedlinks);

	db_open();
	res = db_prepare("SELECT feedlink FROM feeds;");
	while ((step = sqlite3_step(res)) == SQLITE_ROW) {
		feedlink = xcalloc(1, sizeof(struct feedlink));
		feedlink->url = xstrdup((char *) sqlite3_column_text(res, 0));
		TAILQ_INSERT_TAIL(feedlinks, feedlink, next);
	}
	sqlite3_finalize(res);
	db_close();

	return feedlinks;
}

void
feeds_refresh()
{

Changes to src/rss/items.c.

88
89
90
91
92
93
94

95
96
97
98
99
100
101
...
103
104
105
106
107
108
109

110
111
112
113
114
115
116

117

118
119
120
121
122
123
124
{
	sqlite3_stmt *res;
	struct items *items;
	struct item *item;
	char *title, *desc, *published, *guid, *link;
	int step;


	items = items_new();
	res = db_prepare("SELECT title, description, published, guid, link"
				" FROM items"
				" WHERE read = 0");
	while ((step = sqlite3_step(res)) == SQLITE_ROW) {
		title = (char *) sqlite3_column_text(res, 0);
		desc = (char *) sqlite3_column_text(res, 1);
................................................................................
		guid = (char *) sqlite3_column_text(res, 3);
		link = (char *) sqlite3_column_text(res, 4);

		item = item_new(title, desc, published, guid, link);
		TAILQ_INSERT_TAIL(items, item, next);
	}
	sqlite3_finalize(res);


	return items;
}

void
items_mark_read()
{

	db_run("UPDATE items SET read = 1 WHERE read = 0");

}

void
items_unread_browse()
{
	struct items *items;
	struct item *item;







>







 







>







>

>







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
	sqlite3_stmt *res;
	struct items *items;
	struct item *item;
	char *title, *desc, *published, *guid, *link;
	int step;

	db_open();
	items = items_new();
	res = db_prepare("SELECT title, description, published, guid, link"
				" FROM items"
				" WHERE read = 0");
	while ((step = sqlite3_step(res)) == SQLITE_ROW) {
		title = (char *) sqlite3_column_text(res, 0);
		desc = (char *) sqlite3_column_text(res, 1);
................................................................................
		guid = (char *) sqlite3_column_text(res, 3);
		link = (char *) sqlite3_column_text(res, 4);

		item = item_new(title, desc, published, guid, link);
		TAILQ_INSERT_TAIL(items, item, next);
	}
	sqlite3_finalize(res);
	db_close();

	return items;
}

void
items_mark_read()
{
	db_open();
	db_run("UPDATE items SET read = 1 WHERE read = 0");
	db_close();
}

void
items_unread_browse()
{
	struct items *items;
	struct item *item;

Changes to src/rss/rss.c.

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
..
60
61
62
63
64
65
66
67
68
69
70
		"	-r          : refresh items\n", PROGNAME);
	exit(1);
}

int
main(int argc, char *argv[])
{
	db_open();

	int ch;
	while ((ch = getopt(argc, argv, "hlbfrd:a:")) != -1) {
		switch (ch) {
		case 'h':
			usage();
			break;
		case 'l':
................................................................................
	argv += optind;

	if (argc > 0)
		die("unexpected argument");

	items_unread_display();

	db_close();

	return EXIT_SUCCESS;
}







<
<







 







<
<


24
25
26
27
28
29
30


31
32
33
34
35
36
37
..
58
59
60
61
62
63
64


65
66
		"	-r          : refresh items\n", PROGNAME);
	exit(1);
}

int
main(int argc, char *argv[])
{


	int ch;
	while ((ch = getopt(argc, argv, "hlbfrd:a:")) != -1) {
		switch (ch) {
		case 'h':
			usage();
			break;
		case 'l':
................................................................................
	argv += optind;

	if (argc > 0)
		die("unexpected argument");

	items_unread_display();



	return EXIT_SUCCESS;
}