🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #7169

Re: expire performance enhancement

#7169
From: T. William Wells
Date: Thu, 02 May 1996 00:00
330 lines
10533 bytes
In article <4m6tue$5rp@sunrise.gv.ssi1.com>,
Don Lewis <gdonl@gv.ssi1.com> wrote:
: In article <Dqp091.7q3@twwells.com>, T. William Wells <bill@twwells.com> wrote:
: >BTW, the hack I added: a flag X in expire.ctl that says that if
: >an article matches that line then the article gets expired in
: >_all_ the groups it's cross-posted to. This is a space-saver for
: >when someone cross-posts between binaries and non-binaries; it's
: >especially useful if you use -l.  That it also zaps small posts
: >cross-posted into the binaries groups doesn't bother me in the
: >slightest....
:
: And if you keep the *.answers groups longer than discussion groups,
: it expires the FAQ articles from the *.answers groups a lot sooner
: if they are crossposted to their respective discussion groups :-(

It's a tool; if you use it incorrectly, you cut off your fingers.

Since I had three people ask me, I decided to post the patch.
The first hunk is for the hash table size change; everything else
is for the X flag. NB: this really is a hack; it relies on a
global variable to communicate the results back from one of the
functions....

*** src.arc/expire/expire.c     Fri Jan 12 13:48:02 1996
--- src/expire/expire.c Mon Apr 29 23:26:58 1996
***************
*** 26,32 ****
  */
  #define NGH_HASH(Name, p, j)    \
	for (p = Name, j = 0; *p; ) j = (j << 5) + j + *p++
! #define NGH_SIZE      128
  #define NGH_BUCKET(j) &NGHtable[j & (NGH_SIZE - 1)]

  typedef struct _BUFFER {
--- 26,32 ----
  */
  #define NGH_HASH(Name, p, j)    \
	for (p = Name, j = 0; *p; ) j = (j << 5) + j + *p++
! #define NGH_SIZE        2048
  #define NGH_BUCKET(j)   &NGHtable[j & (NGH_SIZE - 1)]

  typedef struct _BUFFER {
***************
*** 44,49 ****
--- 44,50 ----
      time_t              Keep;
      time_t              Default;
      time_t              Purge;
+     int                 Xpost;
  } NEWSGROUP;

  typedef struct _NGHASH {
***************
*** 78,83 ****
--- 79,85 ----
  STATIC long             EXPsaved;
  STATIC NEWSGROUP        *Groups;
  STATIC NEWSGROUP        EXPdefault;
+ STATIC NEWSGROUP        *EXPfound;
  STATIC NGHASH           NGHtable[NGH_SIZE];
  STATIC STRING           EXPreason;
  STATIC time_t           EXPremember;
***************
*** 314,323 ****
  **  Set the expiration fields for all groups that match this pattern.
  */
  STATIC void
! EXPmatch(p, v, mod)
      register char     *p;
      register NEWSGROUP        *v;
      register char     mod;
  {
      register NEWSGROUP        *ngp;
      register int      i;
--- 316,326 ----
  **  Set the expiration fields for all groups that match this pattern.
  */
  STATIC void
! EXPmatch(p, v, mod, xpost)
      register char       *p;
      register NEWSGROUP  *v;
      register char       mod;
+     register int        xpost;
  {
      register NEWSGROUP  *ngp;
      register int        i;
***************
*** 334,339 ****
--- 337,343 ----
		ngp->Keep      = v->Keep;
		ngp->Default   = v->Default;
		ngp->Purge     = v->Purge;
+               ngp->Xpost     = xpost;
		if (EXPverbose > 4) {
		    (void)printf("%s", ngp->Name);
		    (void)printf(" %13.13s", ctime(&v->Keep) + 3);
***************
*** 358,363 ****
--- 362,368 ----
      register int        k;
      register char       mod;
      NEWSGROUP           v;
+     int                 xpost;
      BOOL                SawDefault;
      char                buff[BUFSIZ];
      char                *fields[6];
***************
*** 412,417 ****
--- 417,423 ----
	    (void)fprintf(stderr, "Line %d bad modflag\n", i);
	    return FALSE;
	}
+       xpost = strchr(fields[1], 'X') != NULL;
	if (!EXPgetnum(i, fields[2], &v.Keep,    "keep")
	 || !EXPgetnum(i, fields[3], &v.Default, "default")
	 || !EXPgetnum(i, fields[4], &v.Purge,   "purge"))
***************
*** 449,455 ****
	    return FALSE;
	}
	for (k = 0; k < j; k++)
!           EXPmatch(patterns[k], &v, mod);
      }
      DISPOSE(patterns);

--- 455,461 ----
	    return FALSE;
	}
	for (k = 0; k < j; k++)
!           EXPmatch(patterns[k], &v, mod, xpost);
      }
      DISPOSE(patterns);

***************
*** 527,532 ****
--- 533,540 ----
      *p = '\0';
      if ((ngp = NGfind(Entry)) == NULL)
	ngp = EXPnotfound(Entry);
+     EXPfound = ngp;
+
      *p = '/';

      if (EXPverbose > 2) {
***************
*** 604,622 ****
  **  Do the work of expiring one line.
  */
  STATIC BOOL
! EXPdoline(out, line, length, arts)
      FILE              *out;
      char              *line;
      int                       length;
      char              **arts;
  {
      static char               IGNORING[] = "Ignoring bad line, \"%.20s...\"\n";
      static long               Offset;
      static BUFFER     New;
      register char     *p;
      register char     *q;
-     register char     *first;
      register int      i;
      int                       count;
      char              *fields[4];
      time_t            Arrived;
--- 612,632 ----
  **  Do the work of expiring one line.
  */
  STATIC BOOL
! EXPdoline(out, line, length, arts, flags)
      FILE                *out;
      char                *line;
      int                 length;
      char                **arts;
+     int                 *flags;
  {
      static char         IGNORING[] = "Ignoring bad line, \"%.20s...\"\n";
      static long         Offset;
      static BUFFER       New;
      register char       *p;
      register char       *q;
      register int        i;
+     int                 xflag;
+     int                 keep;
      int                 count;
      char                *fields[4];
      time_t              Arrived;
***************
*** 703,744 ****
	    New.Size = length;
	    RENEW(New.Data, char, New.Size);
	}

!       /* The "first" variable tells us if we haven't saved the first
!        * article yet.  This only matters if we're doing link-saving. */
!       first = EXPlinks && count > 1 ? arts[0] : (char *)NULL;
!
!       /* Loop over all file entries, see if we should keep each one. */
	for (size = -1, q = New.Data, i = 0; i < count; i++) {
	    p = arts[i];
!           if (*p == '\0')
!               /* Shouldn't happen. */
!               continue;
!           if (EXPkeepit(p, when, Expires)) {
		if (EXPverbose > 1)
		    (void)printf("keep %s\n", p);
-               if (first != NULL) {
-                   /* Keeping one and haven't kept the first; so save it. */
-                   if (i > 0)
-                       q += strlen(strcpy(q, first));
-                   first = NULL;
-               }
		if (q > New.Data)
		    *q++ = ' ';
		q += strlen(strcpy(q, p));
!               continue;
!           }
!
!           /* Don't delete the file if preserving symbolic links to it. */
!           if (EXPlinks && i == 0 && count > 1)
!               continue;
	    EXPremove(arts[i], &size);
	}
!
!       /* If saving links and didn't have to save the leader, delete it. */
!       if (EXPlinks && first != NULL)
!           EXPremove(first, &size);
!
	if (q == New.Data) {
	    if (EXPsizing && size > 0)
		EXPsaved += size;
--- 713,758 ----
	    New.Size = length;
	    RENEW(New.Data, char, New.Size);
	}
+       /* First, make a pass over the articles to see which should be
+          expired. */

!       xflag = 0;
!       keep = 0;
!       for (i = 1; i < count; i++) {
!           if (flags[i] = EXPkeepit(arts[i], when, Expires)) {
!               keep = 1;
!           } else if (EXPfound->Xpost) {
!               xflag = 1;
!               break;
!           }
!       }
!       if (!xflag && count > 0) {
!           if (!(flags[0] = EXPkeepit(arts[0], when, Expires))) {
!               if (EXPfound->Xpost) {
!                   xflag = 1;
!               }
!           }
!       }
!       if (xflag) {
!           for (i = 0; i < count; i++) {
!               flags[i] = 0;
!           }
!       } else if (keep && EXPlinks) {
!           flags[0] = 1;
!       }
!       /* Loop over all file entries, get rid of those we don't want. */
	for (size = -1, q = New.Data, i = 0; i < count; i++) {
	    p = arts[i];
!           if (flags[0]) {
		if (EXPverbose > 1)
		    (void)printf("keep %s\n", p);
		if (q > New.Data)
		    *q++ = ' ';
		q += strlen(strcpy(q, p));
!           } else {
		EXPremove(arts[i], &size);
	    }
!       }
	if (q == New.Data) {
	    if (EXPsizing && size > 0)
		EXPsaved += size;
***************
*** 873,878 ****
--- 887,893 ----
      FILE                *F;
      char                *active;
      char                **arts;
+     int                 *flags;
      STRING              History;
      STRING              HistoryText;
      STRING              HistoryPath;
***************
*** 1055,1060 ****
--- 1070,1076 ----

      /* Main processing loop. */
      arts = NEW(char*, nGroups);
+     flags = NEW(int, nGroups);
      if ((qp = QIOopen(HistoryText, QIO_BUFFER)) == NULL) {
	(void)fprintf(stderr, "Can't open history file, %s\n",
		strerror(errno));
***************
*** 1062,1068 ****
      }
      for (Bad = FALSE, line = 1, Paused = FALSE; ; line++) {
	if ((p = QIOread(qp)) != NULL) {
!           if (!EXPdoline(out, p, QIOlength(qp), arts)) {
		Bad = TRUE;
		if (errno == ENOSPC) {
		    (void)unlink(NHistory);
--- 1078,1084 ----
      }
      for (Bad = FALSE, line = 1, Paused = FALSE; ; line++) {
	if ((p = QIOread(qp)) != NULL) {
!           if (!EXPdoline(out, p, QIOlength(qp), arts, flags)) {
		Bad = TRUE;
		if (errno == ENOSPC) {
		    (void)unlink(NHistory);
***************
*** 1101,1106 ****
--- 1117,1123 ----
      }
      QIOclose(qp);
      DISPOSE(arts);
+     DISPOSE(flags);

      if (Writing) {
	/* Close the output files. */



Technical Details
Message-ID: <DqrFKK.DCr@twwells.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
References: <Dqp091.7q3@twwells.com> <4m6tue$5rp@sunrise.gv.ssi1.com>

Show Full Headers
Complete Article Headers
Message-ID: <DqrFKK.DCr@twwells.com>
Subject: Re: expire performance enhancement
Date: Thu, 02 May 1996 00:00:00 +0000
From: bill@twwells.com (T. William Wells)
References: <Dqp091.7q3@twwells.com> <4m6tue$5rp@sunrise.gv.ssi1.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail
X-Deja-AN: 152531307
Organization: None, Mt. Laurel, NJ
Newsgroups: news.software.nntp