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 --- archive.c | 3 ++- archive.h | 1 + bubger.1 | 12 ++++++++++-- concat.c | 15 ++++++++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/archive.c b/archive.c index f55146f..3c5f12b 100644 --- a/archive.c +++ b/archive.c @@ -96,9 +96,10 @@ int main(int argc, char *argv[]) { for ( int opt; - 0 < (opt = getopt(argc, argv, "C:H:S:T:a:h:im:p:qs:tu:vw:y:")); + 0 < (opt = getopt(argc, argv, "A:C:H:S:T:a:h:im:p:qs:tu:vw:y:")); ) { switch (opt) { + break; case 'A': concatIndexEntries = strtoul(optarg, NULL, 10); break; case 'C': { int error = chdir(optarg); if (error) err(EX_NOINPUT, "%s", optarg); diff --git a/archive.h b/archive.h index 5c7dfcf..1a94744 100644 --- a/archive.h +++ b/archive.h @@ -214,6 +214,7 @@ bool exportFetch(FILE *imap, enum Atom tag, struct List threads); bool exportData(FILE *imap, enum Atom tag, struct List items); extern const char *concatHead; +extern size_t concatIndexEntries; void concatFetch(FILE *imap, enum Atom tag, struct List threads); void concatData( struct List threads, struct Envelope *envelopes, struct List items diff --git a/bubger.1 b/bubger.1 index fb349e7..6f0c4d7 100644 --- a/bubger.1 +++ b/bubger.1 @@ -1,4 +1,4 @@ -.Dd March 3, 2021 +.Dd June 9, 2021 .Dt BUBGER 1 .Os . @@ -9,6 +9,7 @@ .Sh SYNOPSIS .Nm .Op Fl iqtv +.Op Fl A Ar entries .Op Fl C Ar path .Op Fl H Ar head .Op Fl S Ar search @@ -40,6 +41,13 @@ is written to standard output. The arguments are as follows: . .Bl -tag -width Ds +.It Fl A Ar entries +Limit the number of entries +in the index Atom feed. +The default limit is 20. +Thread Atom feeds +always contain all entries. +. .It Fl C Ar path Change directory to .Ar path @@ -160,7 +168,7 @@ The IMAP password. .Sh FILES .Bl -tag -width Ds .It Pa index.atom -Rendered Atom feed of all messages. +Rendered Atom feed of recent messages. .It Pa index.html Rendered HTML index of all threads. .It Pa thread/*.atom , Pa thread/*.html , Pa thread/*.mbox 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 ce/commit/bounce.c?h=2.5&id=234ece0547f069cf761bc10262ed74c954e7fb6b&follow=1'>Separate client QUIT and ERROR messagesJune McEnroe 2021-09-02Remove redundant clientDiff functionJune McEnroe 2021-09-02OpenBSD: pledge(2) the genCert code pathJune McEnroe 2021-09-02OpenBSD: pledge(2) the hashPass code pathJune McEnroe 2021-09-02OpenBSD: pledge(2) printCert code path separatelyJune McEnroe 2021-09-02Call serverConfig() with NULLs for -oJune McEnroe 2021-09-02Read from /dev/urandom instead of using getentropy(3)June McEnroe 2021-08-31Separate stateSync intro messagesJune McEnroe 2021-08-30Correct handling of colons in SASL PLAINJune McEnroe 2021-08-28Declare producer staticJune McEnroe 2021-08-28Use CapBits as length of FiltersJune McEnroe 2021-08-21Don't create new tls_server(3), just reconfigureJune McEnroe 2021-08-21Zero local-key memory before freeing itJune McEnroe 2021-08-21Avoid overwriting manual AWAY messagesJune McEnroe 2021-08-20Replace verbose colors with two types of arrowsJune McEnroe 2021-08-20Explicitly clear TLS secrets after handshakeJune McEnroe 2021-08-20Handle TLS_WANT_POLL{IN,OUT} from tls_handshake(3) with serverJune McEnroe 2021-08-20Use "secure" libtls ciphersJune McEnroe 2021-07-08Use seprintf to build final 005June McEnroe 2021-06-19Fix LDADD.crypt on DarwinJune McEnroe 2021-06-18Add -m mode option to set user modesJune McEnroe 2021-06-18Document channel keys in join optionJune McEnroe 2021-06-18Use | to separate flags from config optionsJune McEnroe 2021-06-18Stop referring to server-time as IRCv3.2June McEnroe 2021-06-17Add mailing list archive to READMEJune McEnroe 2021-06-10Stop accumulating ISUPPORT tokens once MOTD startsJune McEnroe 2021-06-09Use seprintf for snip, removing strlcpynJune McEnroe 2021-06-09Use seprintf for reserializeJune McEnroe 2021-06-09Use seprintf for capListJune McEnroe 2021-06-09Add seprintfJune McEnroe 2021-05-27Add pounce-notify to README 2.4June McEnroe 2021-05-27Fix ENVIRONMENT formatting in pounce-notify(1)June McEnroe 2021-05-27Add note about Libera.Chat SASL-only rangesJune McEnroe 2021-05-25Add QUIRKS fileJune McEnroe 2021-05-19Replace freenode with tilde.chatJune McEnroe 2021-05-04notify: Reword pounce-notify manualJune McEnroe 2021-05-02Clean up Makefiles, configure scriptsJune McEnroe 2021-04-30palaver: Exit on getopt failureJune McEnroe 2021-04-30notify: Implement pounce-notifyJune McEnroe