Lock pages table during editing to avoid bogus 404 errors appearing
authorrich <rich>
Thu, 7 Dec 2006 15:46:54 +0000 (15:46 +0000)
committerrich <rich>
Thu, 7 Dec 2006 15:46:54 +0000 (15:46 +0000)
briefly when a page is edited.

scripts/lib/cocanwiki_pages.ml

index 4d17f62..baba26e 100644 (file)
@@ -1,7 +1,7 @@
 (* COCANWIKI - a wiki written in Objective CAML.
  * Written by Richard W.M. Jones <rich@merjis.com>.
  * Copyright (C) 2004 Merjis Ltd.
- * $Id: cocanwiki_pages.ml,v 1.11 2006/08/17 09:11:31 rich Exp $
+ * $Id: cocanwiki_pages.ml,v 1.12 2006/12/07 15:46:54 rich Exp $
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -210,12 +210,12 @@ let save_page r dbh hostid ?user model =
                page_emails_url_cn, links_from_cn, recently_visited_url_cn
              deferred";
 
-      (* Mark the old page as deleted.  NB. There is a small race
-       * condition here because PostgreSQL doesn't do isolation
-       * properly.  If a user tries to visit this page between the
-       * delete and the creation of the new page, then they'll get
-       * a page not found error. (XXX)
+      (* Lock the pages table to avoid bogus 404 errors.  The
+       * lock is released at the end of the current transaction.
        *)
+      PGSQL(dbh) "lock table pages";
+
+      (* Mark the old page as deleted. *)
       PGSQL(dbh) "update pages set url_deleted = url, url = null
                    where hostid = $hostid and id = $model_id";