[PATCH] 'LIST NEWSGROUPS grp' with -n cmd-line switch
Urs Janßen <[email protected]> Mon, 17 Mar 2008 21:41:32 +0100
| Newsgroups | gmane.network.tin.devel |
|---|---|
| Message-ID | <[email protected]> |
use "LIST NEWSGROUPS grp" when using "-n"-cmdline switch if newsrc holds
just a small number of groups (currently a hardcoded limit of 25).
this gives a noticeable speedup on servers with lots of groups but might
slow down things on servers with heavy load and just a few groups...
--- mail.c
+++ mail.c
@@ -41,7 +41,11 @@
#ifndef TCURSES_H
# include "tcurses.h"
#endif /* !TCURSES_H */
-
+#ifdef NNTP_ABLE
+# ifndef TNNTP_H
+# include "tnntp.h"
+# endif /* !TNNTP_H */
+#endif /* NNTP_ABLE */
/*
* local prototypes
*/
@@ -249,6 +253,7 @@
{
#ifdef NNTP_ABLE
FILE *result;
+ static t_bool no_more_wildmat = FALSE;
if (read_news_via_nntp && !read_saved_news) {
if (read_local_newsgroups_file) {
@@ -267,15 +272,56 @@
unlink(local_newsgroups_file);
}
}
-# if 0 /* TODO: */
- if (list_newsgroups_wildmat_supported && newsrc_active
- && !list_active && num_active < some_useful_limit) {
- for_each_group(i) {
- snprintf(buff, sizeof(buff), "LIST NEWSGROUPS %s", active[i].name);
- nntp_command(buff, OK_LIST, NULL, 0);
+# if 1
+ /*
+ * TODO: test me, find a usefull limit,
+ * optimize more than n groups to a wildmat?
+ */
+ if (((nntp_caps.type == CAPABILITIES && nntp_caps.list_newsgroups) | nntp_caps.type != CAPABILITIES) && newsrc_active && !list_active && !no_more_wildmat && num_active < 25) {
+ int resp, i;
+ char buff[NNTP_STRLEN];
+ char line[NNTP_STRLEN];
+ char file[PATH_LEN];
+ char serverdir[PATH_LEN];
+ char *ptr;
+
+ if (nntp_tcp_port != IPPORT_NNTP)
+ snprintf(file, sizeof(file), "%s:%d", nntp_server, nntp_tcp_port);
+ else
+ STRCPY(file, quote_space_to_dash(nntp_server));
+
+ joinpath(serverdir, sizeof(serverdir), rcdir, file);
+ joinpath(file, sizeof(file), serverdir, NEWSGROUPS_FILE".tmp");
+
+ if ((result = fopen(file, "w")) != NULL) {
+ for_each_group(i) {
+ snprintf(buff, sizeof(buff), "LIST NEWSGROUPS %s", active[i].name);
+ put_server(buff);
+ resp = get_respcode(line, sizeof(line));
+ if (resp != OK_GROUPS) {
+ no_more_wildmat = TRUE;
+ break;
+ }
+ while ((ptr = tin_fgets(FAKE_NNTP_FP, FALSE)) != NULL) {
+# ifdef DEBUG
+ if (debug & DEBUG_NNTP)
+ debug_print_file("NNTP", "<<< %s", ptr);
+# endif /* DEBUG */
+ fprintf(result, "%s\n", ptr);
+ }
+ }
+ fclose(result);
+ result = fopen(file, "r");
+ unlink(file); /* unlink on close */
}
+ if (no_more_wildmat) {
+ fclose(result);
+ unlink(file);
+ return (nntp_command("LIST NEWSGROUPS", OK_GROUPS, NULL, 0));
+ } else
+ return result;
} else
-# endif /* 0 */
+# endif /* 1 */
return (nntp_command("LIST NEWSGROUPS", OK_GROUPS, NULL, 0));
} else
#endif /* NNTP_ABLE */