diff options
| author | 2025-01-15 00:40:32 +0000 | |
|---|---|---|
| committer | 2025-01-15 00:40:55 +0000 | |
| commit | b5c5c5cb9e1c728a83596dcc7c4191d012fe1332 (patch) | |
| tree | 85ca79f151cdaf16dc20e4a78e06b9a083c14ffc /mastoapi.c | |
| parent | Don't describe as 'fatal' what are just non-retriable connection errors. (diff) | |
| download | penes-snac2-b5c5c5cb9e1c728a83596dcc7c4191d012fe1332.tar.gz penes-snac2-b5c5c5cb9e1c728a83596dcc7c4191d012fe1332.tar.xz penes-snac2-b5c5c5cb9e1c728a83596dcc7c4191d012fe1332.zip | |
Implement faster min_id handling
Diffstat (limited to 'mastoapi.c')
| -rw-r--r-- | mastoapi.c | 46 |
1 files changed, 28 insertions, 18 deletions
| @@ -1339,6 +1339,9 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn | |||
| 1339 | const char *since_id = xs_dict_get(args, "since_id"); | 1339 | const char *since_id = xs_dict_get(args, "since_id"); |
| 1340 | const char *min_id = xs_dict_get(args, "min_id"); /* unsupported old-to-new navigation */ | 1340 | const char *min_id = xs_dict_get(args, "min_id"); /* unsupported old-to-new navigation */ |
| 1341 | const char *limit_s = xs_dict_get(args, "limit"); | 1341 | const char *limit_s = xs_dict_get(args, "limit"); |
| 1342 | int (*iterator)(FILE *, char *); | ||
| 1343 | int initial_status = 0; | ||
| 1344 | int ascending = 0; | ||
| 1342 | int limit = 0; | 1345 | int limit = 0; |
| 1343 | int cnt = 0; | 1346 | int cnt = 0; |
| 1344 | 1347 | ||
| @@ -1348,27 +1351,40 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn | |||
| 1348 | if (limit == 0) | 1351 | if (limit == 0) |
| 1349 | limit = 20; | 1352 | limit = 20; |
| 1350 | 1353 | ||
| 1351 | if (index_desc_first(f, md5, 0)) { | 1354 | if (min_id) { |
| 1355 | iterator = &index_asc_next; | ||
| 1356 | initial_status = index_asc_first(f, md5, MID_TO_MD5(min_id)); | ||
| 1357 | ascending = 1; | ||
| 1358 | } | ||
| 1359 | else { | ||
| 1360 | iterator = &index_desc_next; | ||
| 1361 | initial_status = index_desc_first(f, md5, 0); | ||
| 1362 | } | ||
| 1363 | |||
| 1364 | if (initial_status) { | ||
| 1352 | do { | 1365 | do { |
| 1353 | xs *msg = NULL; | 1366 | xs *msg = NULL; |
| 1354 | 1367 | ||
| 1355 | /* only return entries older that max_id */ | 1368 | /* only return entries older that max_id */ |
| 1356 | if (max_id) { | 1369 | if (max_id) { |
| 1357 | if (strcmp(md5, MID_TO_MD5(max_id)) == 0) | 1370 | if (strcmp(md5, MID_TO_MD5(max_id)) == 0) { |
| 1358 | max_id = NULL; | 1371 | max_id = NULL; |
| 1359 | 1372 | if (ascending) | |
| 1360 | continue; | 1373 | break; |
| 1374 | } | ||
| 1375 | if (!ascending) | ||
| 1376 | continue; | ||
| 1361 | } | 1377 | } |
| 1362 | 1378 | ||
| 1363 | /* only returns entries newer than since_id */ | 1379 | /* only returns entries newer than since_id */ |
| 1364 | if (since_id) { | 1380 | if (since_id) { |
| 1365 | if (strcmp(md5, MID_TO_MD5(since_id)) == 0) | 1381 | if (strcmp(md5, MID_TO_MD5(since_id)) == 0) { |
| 1366 | break; | 1382 | if (!ascending) |
| 1367 | } | 1383 | break; |
| 1368 | 1384 | since_id = NULL; | |
| 1369 | if (min_id) { | 1385 | } |
| 1370 | if (strcmp(md5, MID_TO_MD5(min_id)) == 0) | 1386 | if (ascending) |
| 1371 | break; | 1387 | continue; |
| 1372 | } | 1388 | } |
| 1373 | 1389 | ||
| 1374 | /* get the entry */ | 1390 | /* get the entry */ |
| @@ -1440,14 +1456,8 @@ xs_list *mastoapi_timeline(snac *user, const xs_dict *args, const char *index_fn | |||
| 1440 | out = xs_list_append(out, st); | 1456 | out = xs_list_append(out, st); |
| 1441 | cnt++; | 1457 | cnt++; |
| 1442 | } | 1458 | } |
| 1443 | if (min_id) { | ||
| 1444 | while (cnt > limit) { | ||
| 1445 | out = xs_list_del(out, 0); | ||
| 1446 | cnt--; | ||
| 1447 | } | ||
| 1448 | } | ||
| 1449 | 1459 | ||
| 1450 | } while ((min_id || (cnt < limit)) && index_desc_next(f, md5)); | 1460 | } while ((cnt < limit) && (*iterator)(f, md5)); |
| 1451 | } | 1461 | } |
| 1452 | 1462 | ||
| 1453 | int more = index_desc_next(f, md5); | 1463 | int more = index_desc_next(f, md5); |