The original code assumes no foreign keys for purposes of cleaning up
disconnected message data. Your main query:
> "DELETE FROM %smessages WHERE status=%d",DBPFX,
> MESSAGE_STATUS_PURGE);
relies on foreign keys to remove the dependent data, or a subsequent run
of dbmail-util to clean out the disconnected parts. That's a totally
reasonable expectation on both counts -- Paul added foreign keys in the
2.2 schemas, and if they're missing for some reason then dbmail-util
will clean out the leftover pieces later.
IMHO, this is a reasonable change to make if Paul has time to review it.
Aaron
On Sat, 2008-12-13 at 20:00 +0100, Michael Monnerie wrote:
> On Freitag 12 Dezember 2008 Paul J Stevens wrote:
> > And as always: patches are most welcome.
>
> I'm not a coder, but I tried figuring out what to do. In
> do_purge_deleted() you just write the text and call db_deleted_purge. I
> quote the function below with my questions.
>
> int db_deleted_purge(u64_t * affected_rows)
> {
> unsigned i;
> char query[DEF_QUERYSIZE];
> memset(query,0,DEF_QUERYSIZE);
>
> u64_t *message_idnrs;
>
> ## what does assert do?
> assert(affected_rows != NULL);
> *affected_rows = 0;
>
> ## the comment speaks about delete of messageblks, but we do a select
> ##from dbmail_messages???
> /* first we're deleting all the messageblks */
> snprintf(query, DEF_QUERYSIZE,
> "SELECT message_idnr FROM %smessages WHERE status=%d",DBPFX,
> MESSAGE_STATUS_PURGE);
> TRACE(TRACE_DEBUG, "executing query [%s]", query);
>
> if (db_query(query) == -1) {
> ## There's a typo "Cound" instead "Could"
> TRACE(TRACE_ERROR, "Cound not fetch message ID numbers");
> return DM_EQUERY;
> }
>
> *affected_rows = db_num_rows();
> if (*affected_rows == 0) {
> TRACE(TRACE_DEBUG, "no messages to purge");
> db_free_result();
> return DM_SUCCESS;
> }
>
> message_idnrs = g_new0(u64_t, *affected_rows);
>
> ## you write about delete here. But db_get_result_u64 doesn't delete,
> ## right? What does it do?
> /* delete each message */
> for (i = 0; i < *affected_rows; i++)
> message_idnrs[i] = db_get_result_u64(i, 0);
>
>
> ## what is db_free_result for?
> db_free_result();
>
> ## here finally the real delete happens, one at a time
> for (i = 0; i < *affected_rows; i++) {
> if (db_delete_message(message_idnrs[i]) == -1) {
> TRACE(TRACE_ERROR, "error deleting message");
> g_free(message_idnrs);
> return DM_EQUERY;
> }
> }
> g_free(message_idnrs);
>
> return DM_EGENERAL;
> }
>
>
> Couldn't we reduce the function to
> int db_deleted_purge(u64_t * affected_rows)
> {
> unsigned i;
> char query[DEF_QUERYSIZE];
> memset(query,0,DEF_QUERYSIZE);
>
> snprintf(query, DEF_QUERYSIZE,
> "DELETE FROM %smessages WHERE status=%d",DBPFX,
> MESSAGE_STATUS_PURGE);
> TRACE(TRACE_DEBUG, "executing query [%s]", query);
>
> if (db_query(query) == -1) {
> TRACE(TRACE_ERROR, "Could not delete messages");
> return DM_EQUERY;
> }
> ## this or something similar to get the number of deleted rows
> ## I don't know what function exists
> *affected_rows=query_num_deleted_records();
> return DM_EGENERAL;
> }
>
> mfg zmi
> _______________________________________________
> DBmail mailing list
> [email protected]
> https://mailman.fastxs.nl/mailman/listinfo/dbmail
_______________________________________________
DBmail mailing list
[email protected]
https://mailman.fastxs.nl/mailman/listinfo/dbmail