- added a new function to the database interface, cdb_close_cursor(). always
authorNathan Bryant <loanshark@uncensored.citadel.org>
Sun, 29 Jul 2001 22:24:04 +0000 (22:24 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Sun, 29 Jul 2001 22:24:04 +0000 (22:24 +0000)
call this when you're finished with a traversal but didn't bother reading all
the way to the end.

 - removed several cdb_begin_transaction()/cdb_end_transaction() calls that are
no longer needed because of the read-only cursor support.

citadel/ChangeLog
citadel/database.c
citadel/database.h
citadel/database_sleepycat.c
citadel/room_ops.c
citadel/serv_expire.c
citadel/serv_upgrade.c
citadel/serv_vandelay.c
citadel/user_ops.c

index 4066afaaf8fe6df559498e05faf24d4c3e54a4eb..8149fe4843fbcbe0a0d922037e6dd458ef93b681 100644 (file)
@@ -1,4 +1,12 @@
  $Log$
+ Revision 580.15  2001/07/29 22:24:04  nbryant
+  - added a new function to the database interface, cdb_close_cursor().  always
+ call this when you're finished with a traversal but didn't bother reading all
+ the way to the end.
+
+  - removed several cdb_begin_transaction()/cdb_end_transaction() calls that are
+ no longer needed because of the read-only cursor support.
+
  Revision 580.14  2001/07/29 20:56:09  nbryant
  change ForEachRoom to use read-only cursors by default. it can be overridden to
  still use read/write cursors by doing:
@@ -2633,3 +2641,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import 
+
index dc247df978a194ad2c98af31403a0e7013d942ce..7bb650384037c473d837972350cdb78e896f8cba 100644 (file)
@@ -278,6 +278,28 @@ void cdb_free(struct cdbdata *cdb)
        phree(cdb);
 }
 
+void cdb_close_cursor(cdb)
+{
+        while (max_keys <= CC->cs_pid) {
+                ++max_keys;
+                if (dtkey == NULL) {
+                        dtkey = (datum *)
+                            mallok((sizeof(datum) * max_keys));
+                } else {
+                        dtkey = (datum *)
+                            reallok(dtkey, (sizeof(datum) * max_keys));
+                }
+                dtkey[max_keys - 1].dsize = 0;
+                dtkey[max_keys - 1].dptr = NULL;
+        }
+
+        if (dtkey[CC->cs_pid].dptr != NULL) {
+                phree(dtkey[CC->cs_pid].dptr);
+        }
+       dtkey[CC->cs_pid].dptr = NULL;
+       dtkey[CC->cs_pid].dsize = 0;
+}
+
 
 /* 
  * Prepare for a sequential search of an entire database.  (In the gdbm model,
index b4dbc6f4725b10c7875c101ea2c3af2c4d4867a4..ba74d70a5bc13fc7622b22cbe2f9a403fed2e27c 100644 (file)
@@ -8,6 +8,7 @@ struct cdbdata *cdb_fetch (int cdb, void *key, int keylen);
 void cdb_free (struct cdbdata *cdb);
 void cdb_rewind (int cdb);
 struct cdbdata *cdb_next_item (int cdb);
+void cdb_close_cursor(int cdb);
 void cdb_begin_transaction(void);
 void cdb_end_transaction(void);
 void cdb_allocate_tsd(void);
index 3c52989ae995a06df8c54cd35cf064b6671d07e0..8579e733228bff894402e5aa60040b7b02caec41 100644 (file)
@@ -570,6 +570,13 @@ void cdb_free(struct cdbdata *cdb)
        phree(cdb);
 }
 
+void cdb_close_cursor(int cdb)
+{
+       if (MYCURSORS[cdb] != NULL)
+               cclose(MYCURSORS[cdb]);
+
+       MYCURSORS[cdb] = NULL;
+}
 
 /* 
  * Prepare for a sequential search of an entire database.
index 3566a66ec72b0e0c991e3df9dd7b5ad341324d7f..51b8cf4c081da7fcb352eee4f716be68362698ce 100644 (file)
@@ -839,7 +839,6 @@ void cmd_whok(void)
        struct usersupp temp;
        struct cdbdata *cdbus;
 
-       cdb_begin_transaction();
        getuser(&CC->usersupp, CC->curr_user);
        if (CtdlAccessCheck(ac_room_aide)) return;
 
@@ -855,7 +854,6 @@ void cmd_whok(void)
                    )
                        cprintf("%s\n", temp.fullname);
        }
-       cdb_end_transaction();
        cprintf("000\n");
 }
 
@@ -1335,11 +1333,6 @@ unsigned create_room(char *new_room_name,
         */
        if (!really_create) return (qrbuf.QRflags);
 
-       /* cdb_begin_transaction();  commented out because a transaction
-          is already open when creating __CtdlSMTPspoolout__ while
-          initializing serv_smtp.c
-        */
-
        qrbuf.QRnumber = get_new_room_number();
        qrbuf.QRhighest = 0L;   /* No messages in this room yet */
        time(&qrbuf.QRgen);     /* Use a timestamp as the generation number */
@@ -1362,7 +1355,6 @@ unsigned create_room(char *new_room_name,
        lputuser(&CC->usersupp);
 
        /* resume our happy day */
-       /* cdb_end_transaction(); */
        return (qrbuf.QRflags);
 }
 
index 149ad0e6cfaf9b378daa16dd78ca4baf6ef0d719..e153b99bfb26faf3e09d5e4e9a51a4a6f02768c6 100644 (file)
@@ -475,7 +475,6 @@ int PurgeVisits(void) {
        ForEachUser(AddValidUser, NULL);
 
        /* Now traverse through the visits, purging irrelevant records... */
-       cdb_begin_transaction();
        cdb_rewind(CDB_VISIT);
        while(cdbvisit = cdb_next_item(CDB_VISIT), cdbvisit != NULL) {
                memset(&vbuf, 0, sizeof(struct visit));
@@ -513,8 +512,6 @@ int PurgeVisits(void) {
 
        }
 
-       cdb_end_transaction();
-
        /* Free the valid room/gen combination list */
        while (ValidRoomList != NULL) {
                vrptr = ValidRoomList->next;
index 17730bd3595735ab424ce9b8f386e11db0ceae57..1b03efb2f66a8a0af3f97febf05f212c1c01b96a 100644 (file)
@@ -59,7 +59,6 @@ void do_pre555_usersupp_upgrade(void) {
        strcpy(tempfilename, tmpnam(NULL));
 
        /* First, back out all old version records to a flat file */
-       cdb_begin_transaction();
         cdb_rewind(CDB_USERSUPP);
         while(cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
                 memset(&usbuf, 0, sizeof(struct pre555usersupp));
@@ -69,7 +68,6 @@ void do_pre555_usersupp_upgrade(void) {
                 cdb_free(cdbus);
                fwrite(&usbuf, sizeof(struct pre555usersupp), 1, fp);
        }
-       cdb_end_transaction();
 
        /* ...and overwrite the records with new format records */
        rewind(fp);
index bc54ced0fd159076fe49afd938bad97a324d8ddd..bd613e0c0cd544d2f40fa534c248207bfb7907ad 100644 (file)
@@ -155,7 +155,6 @@ void artv_export_visits(void) {
        struct visit vbuf;
        struct cdbdata *cdbv;
 
-       cdb_begin_transaction();
        cdb_rewind(CDB_VISIT);
 
        while (cdbv = cdb_next_item(CDB_VISIT), cdbv != NULL) {
@@ -179,7 +178,6 @@ void artv_export_visits(void) {
 
                cprintf("%u\n", vbuf.v_flags);
        }
-       cdb_end_transaction();
 }
 
 
index ce4b0b33e4ed0657ea0627b4164c7f5ba45a0d88..2cbcb0c8648a240ca21f6fcc256e7eb6dea57abb 100644 (file)
@@ -280,7 +280,6 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
 {
        struct cdbdata *cdbus;
 
-       cdb_begin_transaction();
        cdb_rewind(CDB_USERSUPP);
 
        while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
@@ -290,11 +289,10 @@ int getuserbynumber(struct usersupp *usbuf, long int number)
                        sizeof(struct usersupp) : cdbus->len));
                cdb_free(cdbus);
                if (usbuf->usernum == number) {
-                       cdb_end_transaction();
+                       cdb_close_cursor(CDB_USERSUPP);
                        return (0);
                }
        }
-       cdb_end_transaction();
        return (-1);
 }
 
@@ -1006,7 +1004,6 @@ void cmd_gnur(void)
        /* There are unvalidated users.  Traverse the usersupp database,
         * and return the first user we find that needs validation.
         */
-       cdb_begin_transaction();
        cdb_rewind(CDB_USERSUPP);
        while (cdbus = cdb_next_item(CDB_USERSUPP), cdbus != NULL) {
                memset(&usbuf, 0, sizeof(struct usersupp));
@@ -1017,11 +1014,10 @@ void cmd_gnur(void)
                if ((usbuf.flags & US_NEEDVALID)
                    && (usbuf.axlevel > 0)) {
                        cprintf("%d %s\n", MORE_DATA, usbuf.fullname);
-                       cdb_end_transaction();
+                       cdb_close_cursor(CDB_USERSUPP);
                        return;
                }
        }
-       cdb_end_transaction();
 
        /* If we get to this point, there are no more unvalidated users.
         * Therefore we clear the "users need validation" flag.