]> git.pond.sub.org Git - empserver/commitdiff
Record news more compactly
authorMarkus Armbruster <armbru@pond.sub.org>
Thu, 31 Dec 2009 08:18:37 +0000 (09:18 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Tue, 19 Jan 2010 07:21:56 +0000 (08:21 +0100)
Member nws_uid is unused since the commit before previous.  Remove it.

Member nws_seqno is of marginal value, because we write news only
through ncache[], and thus aren't prone to the errors sequence numbers
can catch.  Remove it.

Make timestamp selector virtual, computing nws_when + nws_duration,
and remove member nws_timestamp.  Impact:

* In ncache(), the removed timestamp equals nws_when + nws_duration,
  both for new news and updated news.  No change.

* delete_old_news() becomes invisible.  Before, its move of unexpired
  news to the beginning of the news file touched all the timestamps.
  That was unwanted, because the move does not change news, only their
  storage.  Improvement.

* empdump no longer flags the imported news changed via the timestamp.
  This is somewhat unfortunate.  Document as bug.

With these members removed, struct nwsstr no longer matches struct
emptypedstr, so clear news table flag EFF_TYPED and remove union
empobj_storage member news.  This loses the automatic maintenance of
member ef_type via struct emptypedstr.  Remove ef_type as well.

This shrinks struct nwsstr from 20 to 12 bytes on common 32 bit
machines, and from 32 to 16 bytes on common 64 bit machines.  Since
the server doesn't map the whole news file (EFF_MAP is off), this
reduces I/O, while the table's memory use remains the same.

Historical note: struct nwsstr is now pretty much what it was back in
BSD Empire 1.1.  Members ef_type and nws_uid go back to Empire 3 (for
C_SYNC?).  v4.3.12 added member nws_timestamp, which doubled the size
on common 64 bit machines.  v4.3.15 added nws_seqno.

include/empobj.h
include/news.h
info/xdump.t
src/lib/common/filetable.c
src/lib/common/nsc.c
src/lib/subs/nreport.c

index 713f2f4a50e118773e748c849faaf291d8bd9200..373ec0212ea745376a556258bee78b6ad0f7f155 100644 (file)
@@ -84,7 +84,6 @@ union empobj_storage {
     struct lonstr loan;
     struct loststr lost;
     struct natstr nat;
-    struct nwsstr news;
     struct nukstr nuke;
     struct plnstr plane;
     struct realmstr realm;
index 54d7ef9f09b3f5cbf60d415ae983e32a0cb35eba..b6853a99e286a5b92485e6d3b972b729fc7932dc 100644 (file)
 #include "nsc.h"
 
 struct nwsstr {
-    /* initial part must match struct empobj */
-    short ef_type;
-    short nws_uid;
-    unsigned nws_seqno;
-    time_t nws_timestamp;
-    /* end of part matching struct empobj */
     natid nws_ano;             /* "actor" country # */
     unsigned char nws_vrb;     /* action (verb) */
     natid nws_vno;             /* "victim" country # */
index 95ab16008796b2df103678e39e9426ec1d5ea6af..4521c71225294bbbdcf67644e8c79536774f2978 100644 (file)
@@ -97,6 +97,8 @@ yet available in human-readable form: the lost file, sect-chr selector
 nav, ship and land plague status (deity only), plane theta (governs
 satellite movement), trade selectors xloc, yloc, commodity selectors
 xbuy, ybuy.
+Incremental dump doesn't work after importing news with the empdump
+utility.
 .s1
 .L "FUTURE DIRECTIONS:"
 xdump is still fairly new, and experience with it may lead to changes.
index 100c3f4700d4daea20d1b5ca0f3c54b9a93e3251..8bfb1bbfd1a69c2d492c55c56a21988f2b0d4a89 100644 (file)
@@ -133,7 +133,7 @@ struct empfile empfile[] = {
     {EF_NUKE, "nuke", "nuke", nuke_ca,
      UNMAPPED_CACHE(struct nukstr, EFF_TYPED | EFF_XY | EFF_OWNER)},
     {EF_NEWS, "news", "news", news_ca,
-     UNMAPPED_CACHE(struct nwsstr, EFF_TYPED)},
+     UNMAPPED_CACHE(struct nwsstr, 0)},
     {EF_TREATY, "treaty", "treaty", treaty_ca,
      UNMAPPED_CACHE(struct trtstr, EFF_TYPED)},
     {EF_TRADE, "trade", "trade", trade_ca,
index eb0348ee9574905790bcc065c2011ea6c26a844a..c237b5e0fd7a550773b4cee45f2bdd04c6f3372e 100644 (file)
@@ -67,6 +67,7 @@ static void *nsc_lnd_acc(struct valstr *, struct natstr *, void *);
 static void *nsc_lnd_dam(struct valstr *, struct natstr *, void *);
 static void *nsc_lnd_aaf(struct valstr *, struct natstr *, void *);
 static void *nsc_lchr(struct valstr *, struct natstr *, void *);
+static void *nsc_nws_timestamp(struct valstr *, struct natstr *, void *);
 
 /* Ugly hack to improve legibility by avoid long lines */
 #define fldoff(fld) offsetof(CURSTR, fld)
@@ -468,9 +469,7 @@ struct castr loan_ca[] = {
 
 struct castr news_ca[] = {
 #define CURSTR struct nwsstr
-    /* no need for uid as long as it's not referenced from other tables */
-    {"timestamp", fldoff(nws_timestamp), NSC_TIME, 0, NULL,
-     EF_BAD, NSC_EXTRA},
+    {"timestamp", 0, NSC_LONG, 0, nsc_nws_timestamp, EF_BAD, NSC_EXTRA},
     {"actor", fldoff(nws_ano), NSC_NATID, 0, NULL, EF_NATION, 0},
     {"action", fldoff(nws_vrb), NSC_UCHAR, 0, NULL, EF_NEWS_CHR, 0},
     {"victim", fldoff(nws_vno), NSC_NATID, 0, NULL, EF_NATION, 0},
@@ -915,3 +914,12 @@ nsc_lchr(struct valstr *val, struct natstr *np, void *ptr)
     val->val_as.sym.get = NULL;
     return lchr + ((struct lndstr *)ptr)->lnd_type;
 }
+
+static void *
+nsc_nws_timestamp(struct valstr *val, struct natstr *natp, void *ptr)
+{
+    struct nwsstr *np = ptr;
+
+    val->val_as.lng = np->nws_when + np->nws_duration;
+    return NULL;
+}
index 2d92aa8a132ebbfe5604605c956c6dd8783813d4..cfb5641bdac625c3bc75d2f378125a7258b26fc9 100644 (file)
@@ -117,7 +117,6 @@ delete_old_news(void)
     for (j = 0; getnews(i + j, &news); j++) {
        if (news.nws_vrb == 0)
            break;
-       ef_set_uid(EF_NEWS, &news, j);
        putnews(j, &news);
     }
     CANT_HAPPEN(i + j != news_tail);