- if (smr.len == 0) {
- if (Reply) {
- cprintf("%d Unable to serialize message\n", ERROR + INTERNAL_ERROR);
- }
- else {
- syslog(LOG_ERR, "msgbase: CtdlSaveMessage() unable to serialize message");
+ // STORAGE STRATEGY:
+ // * If headers+content fit are <= 4K, store them together. It's likely to be one
+ // memory page, one disk sector, etc. so we benefit from a single disk operation.
+ // * If headers+content exceed 4K, store them separately so we don't end up fetching
+ // many gigamegs of data when we're just scanning the headers.
+ // * We are using a threshold of 4000 bytes so that there's some room for overhead
+ // if the database or OS adds any metadata to that one disk page.
+
+ if (smr.len <= 4000) { // all together less than one page, store them together
+
+ if (cdb_store(CDB_MSGMAIN, &msgid, (int)sizeof(long), smr.ser, smr.len)) {
+ ++error_count;