X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Flargest_pages.ml;h=161d12a63e2146db36be5772a2911c14c276beb8;hb=cd059731a60fd3d4dcf426430ad26ff227b91910;hp=13e04135594d81371cb1e8d29e8b3afda2c1d153;hpb=bfa88724ee152ba00c2b2fca881dd78a6599820a;p=cocanwiki.git diff --git a/scripts/largest_pages.ml b/scripts/largest_pages.ml index 13e0413..161d12a 100644 --- a/scripts/largest_pages.ml +++ b/scripts/largest_pages.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: largest_pages.ml,v 1.4 2006/03/27 18:09:46 rich Exp $ + * $Id: largest_pages.ml,v 1.6 2006/03/28 16:24:07 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 @@ -39,34 +39,36 @@ let run r (q : cgi) dbh hostid _ _ = * approximation of the final size of the page. Also, we are not taking * into account images. *) - let sth = - dbh#prepare_cached + let rows = + PGSQL(dbh) "select p.id, p.url, p.title, sum (length (c.content)) from pages p, contents c - where p.hostid = ? and p.url is not null and p.redirect is null + where p.hostid = $hostid and p.url is not null and p.redirect is null and c.pageid = p.id group by 1, 2, 3 order by 4 desc" in - sth#execute [Some hostid]; let table = - sth#map - (function [Some pageid; Some page; Some title; Some size] -> - let download_time = overhead + size / modem_speed in (* seconds *) - let download_time = - if download_time <= 4 then "<= 4 s" - else if download_time < 60 then sprintf "%d s" download_time - else sprintf "%d m %d s" (download_time / 60) (download_time mod 60) - in + List.map + (fun (pageid, page, title, size) -> + let page = Option.get page in + let size = Int64.to_int (Option.get size) in + let download_time = overhead + size / modem_speed in (* seconds *) + let download_time = + if download_time <= 4 then "<= 4 s" + else if download_time < 60 then sprintf "%d s" download_time + else + sprintf "%d m %d s" (download_time / 60) (download_time mod 60) + in - let size = - if size < 4096 then sprintf "%d bytes" size - else sprintf "%d K" (size / 1024) in + let size = + if size < 4096 then sprintf "%d bytes" size + else sprintf "%d K" (size / 1024) in - [ "pageid", Template.VarString (Int32.to_string pageid); - "page", Template.VarString page; - "title", Template.VarString title; - "size", Template.VarString size; - "download_time", Template.VarString download_time ] - | _ -> assert false) in + [ "pageid", Template.VarString (Int32.to_string pageid); + "page", Template.VarString page; + "title", Template.VarString title; + "size", Template.VarString size; + "download_time", Template.VarString download_time ] + ) rows in template#table "pages" table; q#template template