diff options
author | June McEnroe <june@causal.agency> | 2021-06-09 17:20:17 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2021-06-09 17:20:17 -0400 |
commit | 92b58f22afbf44f4b87ce9856c6fd14b1f04da37 (patch) | |
tree | 37a8be58b361221e8413ccc8af96b0f49dceed43 /concat.c | |
parent | Use LDADD variables and BINDIR (diff) | |
download | bubger-92b58f22afbf44f4b87ce9856c6fd14b1f04da37.tar.gz bubger-92b58f22afbf44f4b87ce9856c6fd14b1f04da37.zip |
Limit number of entries in index Atom feed
Diffstat (limited to '')
-rw-r--r-- | concat.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/concat.c b/concat.c index 64e543f..3e03f3b 100644 --- a/concat.c +++ b/concat.c @@ -230,13 +230,19 @@ void concatThreads(struct List threads, const struct Envelope *envelopes) { } } +static int numberCompare(const void *_a, const void *_b) { + const struct Data *a = _a; + const struct Data *b = _b; + return (b->number > a->number) - (b->number < a->number); +} + struct Sort { size_t index; time_t updated; time_t created; }; -static int compar(const void *_a, const void *_b) { +static int sortCompare(const void *_a, const void *_b) { const struct Sort *a = _a; const struct Sort *b = _b; if (a->updated == b->updated) { @@ -246,6 +252,8 @@ static int compar(const void *_a, const void *_b) { } } +size_t concatIndexEntries = 20; + void concatIndex(struct List threads, const struct Envelope *envelopes) { const char *path = "index.atom"; FILE *file = fopen(path, "w"); @@ -256,7 +264,8 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) { struct List flat = {0}; listFlatten(&flat, threads); - for (size_t i = flat.len - 1; i < flat.len; --i) { + qsort(flat.ptr, flat.len, sizeof(*flat.ptr), numberCompare); + for (size_t i = 0; i < flat.len && i < concatIndexEntries; ++i) { uint32_t uid = dataCheck(flat.ptr[i], Number).number; char *src = uidPath(uid, "atom"); error = concatFile(file, src); @@ -283,7 +292,7 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) { order[i].created = envelopes[i].time; order[i].updated = status.st_mtime; } - qsort(order, threads.len, sizeof(*order), compar); + qsort(order, threads.len, sizeof(*order), sortCompare); path = "index.html"; file = fopen(path, "w"); |