| 1369 | } |
| 1370 | |
| 1371 | static struct command_result *refresh_tables(struct command *cmd, |
| 1372 | struct db_query *dbq) |
| 1373 | { |
| 1374 | struct table_desc *td; |
| 1375 | |
| 1376 | if (tal_count(dbq->tables) == 0) |
| 1377 | return refresh_complete(cmd, dbq); |
| 1378 | |
| 1379 | td = dbq->tables[0]; |
| 1380 | |
| 1381 | /* If it's currently being refreshed, wait */ |
| 1382 | if (td->refreshing) { |
| 1383 | struct refresh_waiter *rw = tal(cmd, struct refresh_waiter); |
| 1384 | rw->cmd = cmd; |
| 1385 | rw->dbq = dbq; |
| 1386 | list_add(&td->refresh_waiters, &rw->list); |
| 1387 | return command_still_pending(cmd); |
| 1388 | } |
| 1389 | |
| 1390 | if (td->refresh_needs == REFRESH_UNNECESSARY) |
| 1391 | return next_refresh(cmd, dbq); |
| 1392 | |
| 1393 | td->refreshing = true; |
| 1394 | td->refresh_start = time_mono(); |
| 1395 | |
| 1396 | /* The first time, we may need to install watches */ |
| 1397 | if (!td->populated && td->waitname) { |
| 1398 | /* We will initialize td->last_created_index as we read them in */ |
| 1399 | watch_init(cmd, td, "created", NULL); |
| 1400 | watch_init(cmd, td, "updated", &td->last_updated_index); |
| 1401 | watch_init(cmd, td, "deleted", NULL); |
| 1402 | } |
| 1403 | |
| 1404 | return td->refresh(cmd, dbq->tables[0], dbq); |
| 1405 | } |
| 1406 | |
| 1407 | static struct command_result *json_sql(struct command *cmd, |
| 1408 | const char *buffer, |
no test coverage detected