put_visit() no longer needs a separate function to generate its index.
authorArt Cancro <ajc@citadel.org>
Tue, 2 May 2023 22:29:48 +0000 (18:29 -0400)
committerArt Cancro <ajc@citadel.org>
Tue, 2 May 2023 22:29:48 +0000 (18:29 -0400)
it is simply the first (sizeof(long)*3) bytes of the structure.

citadel/server/server.h
citadel/server/user_ops.c
citadel/server/user_ops.h
citadel/utils/ctdl3264.c

index 4ded3617956a49714da533af39c222d6d857b1d4..982a2749c71df4b68cd42b094a6ce2967fc61d47 100644 (file)
@@ -77,9 +77,9 @@ struct cdbdata {
 // NOTE: if you add fields to this, you have to also write export/import code in server/modules/migrate/serv_migrate.c
 // NOTE: if you add fields to this, you have to also write conversion code in utils/ctdl3264/*
 struct visit {
-       long v_roomnum;
-       long v_roomgen;
-       long v_usernum;
+       long v_roomnum;         //
+       long v_roomgen;         // The first three fields , sizeof(long)*3 , are the index format.
+       long v_usernum;         //
        long v_lastseen;
        unsigned v_flags;
        char v_seen[SIZ];
@@ -88,6 +88,14 @@ struct visit {
 };
 
 
+// This is the db index format for "visit" records, which describe the relationship between one user and one room.
+struct visit_index {
+       long iRoomID;
+       long iRoomGen;
+       long iUserID;
+};
+
+
 // Supplementary data for a message on disk
 // These are kept separate from the message itself for one of two reasons:
 // 1. Either their values may change at some point after initial save, or
@@ -210,12 +218,4 @@ struct CtdlCompressHeader {
 };
 
 
-// This is the db index format for "visit" records, which describe the relationship between one user and one room.
-struct visit_index {
-       long iRoomID;
-       long iRoomGen;
-       long iUserID;
-};
-
-
 #endif // SERVER_H
index 99bf5b0229f1cbda915430aef94bed937bc24cc0..e5eddf0698a0b854f3392429015921f0ddce5319 100644 (file)
@@ -235,18 +235,9 @@ int GenerateRelationshipIndex(char *IndexBuf, long RoomID, long RoomGen, long Us
        return(sizeof(TheIndex));
 }
 
-
 // Back end for CtdlSetRelationship()
 void put_visit(struct visit *newvisit) {
-       char IndexBuf[32];
-       int IndexLen = 0;
-
-       memset(IndexBuf, 0, sizeof (IndexBuf));
-       // Generate an index
-       IndexLen = GenerateRelationshipIndex(IndexBuf, newvisit->v_roomnum, newvisit->v_roomgen, newvisit->v_usernum);
-
-       // Store the record
-       cdb_store(CDB_VISIT, IndexBuf, IndexLen, newvisit, sizeof(struct visit));
+       cdb_store(CDB_VISIT, newvisit, (sizeof(long)*3), newvisit, sizeof(struct visit));
 }
 
 
@@ -258,23 +249,24 @@ void CtdlSetRelationship(struct visit *newvisit, struct ctdluser *rel_user, stru
        newvisit->v_roomgen = rel_room->QRgen;
        newvisit->v_usernum = rel_user->usernum;
 
+       // Store the record
        put_visit(newvisit);
 }
 
 
 // Locate a relationship between a user and a room
 void CtdlGetRelationship(struct visit *vbuf, struct ctdluser *rel_user, struct ctdlroom *rel_room) {
-       char IndexBuf[32];
-       int IndexLen;
        struct cdbdata *cdbvisit;
 
-       // Generate an index
-       IndexLen = GenerateRelationshipIndex(IndexBuf, rel_room->QRnumber, rel_room->QRgen, rel_user->usernum);
-
        // Clear out the buffer
        memset(vbuf, 0, sizeof(struct visit));
 
-       cdbvisit = cdb_fetch(CDB_VISIT, IndexBuf, IndexLen);
+       // Fill out the first three fields; they are also the index
+       vbuf->v_roomnum = rel_room->QRnumber;
+       vbuf->v_roomgen = rel_room->QRgen;
+       vbuf->v_usernum = rel_user->usernum;
+
+       cdbvisit = cdb_fetch(CDB_VISIT, vbuf, (sizeof(long)*3));
        if (cdbvisit != NULL) {
                memcpy(vbuf, cdbvisit->ptr, ((cdbvisit->len > sizeof(struct visit)) ?  sizeof(struct visit) : cdbvisit->len));
                cdb_free(cdbvisit);
index ffcc0e857a7f5b0b4417952b8208592d8c43820e..b7296ab8816071ad6d123242f39b867939abb145 100644 (file)
@@ -38,8 +38,8 @@ int CtdlInvtKick(char *iuser, int op);
 void ForEachUser(void (*CallBack) (char *, void *out_data), void *in_data);
 int NewMailCount(void);
 int InitialMailCheck(void);
-void put_visit(struct visit *newvisit);
 int GenerateRelationshipIndex(char *IndexBuf, long RoomID, long RoomGen, long UserID);
+void put_visit(struct visit *);
 int CtdlAssociateSystemUser(char *screenname, char *loginname);
 
 void CtdlSetPassword(char *new_pw);
index 57ddfcc0e7ce1651c9ec7e705acd5bf502ff1f1a..3669bdfe0e38027d861bb9f1b40982550c10462a 100644 (file)
@@ -317,7 +317,7 @@ void convert_visits(int which_cdb, DBT *in_key, DBT *in_data, DBT *out_key, DBT
 
        printf("\033[32m\033[1mVisit: room %ld, gen %ld, user %ld\033[0m\n", visit64->v_roomnum, visit64->v_roomgen, visit64->v_usernum);
 
-       // create the key (which is based on the data, so there is no need to  the old key)
+       // create the key (which is based on the data, so there is no need to convert the old key)
        out_key->size = sizeof(struct visit_index);
        out_key->data = realloc(out_key->data, out_key->size);
        struct visit_index *newvisitindex = (struct visit_index *) out_key->data;
@@ -560,6 +560,8 @@ void convert_table(int which_cdb, DB_ENV *src_dbenv, DB_ENV *dst_dbenv) {
        DBT in_key, in_data, out_key, out_data, uncomp_data, recomp_data;
        int num_rows = 0;
 
+       snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
+
        // create a database handle for the source table
        ret = db_create(&src_dbp, src_dbenv, 0);
        if (ret) {
@@ -569,8 +571,6 @@ void convert_table(int which_cdb, DB_ENV *src_dbenv, DB_ENV *dst_dbenv) {
        }
 
        // open the file containing the source table
-       snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
-       printf("\033[33m\033[1mdb: opening source %s\033[0m\n", dbfilename);
        ret = src_dbp->open(src_dbp, NULL, dbfilename, NULL, DB_BTREE, 0, 0600);
        if (ret) {
                printf("db: db_open: %s\n", db_strerror(ret));
@@ -587,7 +587,6 @@ void convert_table(int which_cdb, DB_ENV *src_dbenv, DB_ENV *dst_dbenv) {
        }
 
        // open the file containing the destination table
-       snprintf(dbfilename, sizeof dbfilename, "cdb.%02x", which_cdb);
        printf("\033[33m\033[1mdb: opening destination %s\033[0m\n", dbfilename);
        ret = dst_dbp->open(dst_dbp, NULL, dbfilename, NULL, DB_BTREE, (DB_CREATE | DB_TRUNCATE), 0600);
        if (ret) {