From: Art Cancro Date: Tue, 2 May 2023 22:29:48 +0000 (-0400) Subject: put_visit() no longer needs a separate function to generate its index. X-Git-Tag: v976~12 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=acabe560a31af729e82b2b4581a340d028af0756;p=citadel.git put_visit() no longer needs a separate function to generate its index. it is simply the first (sizeof(long)*3) bytes of the structure. --- diff --git a/citadel/server/server.h b/citadel/server/server.h index 4ded36179..982a2749c 100644 --- a/citadel/server/server.h +++ b/citadel/server/server.h @@ -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 diff --git a/citadel/server/user_ops.c b/citadel/server/user_ops.c index 99bf5b022..e5eddf069 100644 --- a/citadel/server/user_ops.c +++ b/citadel/server/user_ops.c @@ -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); diff --git a/citadel/server/user_ops.h b/citadel/server/user_ops.h index ffcc0e857..b7296ab88 100644 --- a/citadel/server/user_ops.h +++ b/citadel/server/user_ops.h @@ -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); diff --git a/citadel/utils/ctdl3264.c b/citadel/utils/ctdl3264.c index 57ddfcc0e..3669bdfe0 100644 --- a/citadel/utils/ctdl3264.c +++ b/citadel/utils/ctdl3264.c @@ -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) {