From 92b58f22afbf44f4b87ce9856c6fd14b1f04da37 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 9 Jun 2021 17:20:17 -0400 Subject: Limit number of entries in index Atom feed --- concat.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'concat.c') 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"); -- cgit 1.4.1