Changeset 14916 in project


Ignore:
Timestamp:
06/06/09 19:01:23 (10 years ago)
Author:
azul
Message:

For the <weblogabout/> tag, include a 'The following are the best rated posts in this weblog' section. Also profile the svnwiki-rating-get-best-posts function. Other small improvements.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/3/svnwiki-rating/trunk/svnwiki-rating.scm

    r14098 r14916  
    44
    55(declare (export))
    6 (use svnwiki-extensions-support srfi-40 html-stream stream-ext format-modular orders srfi-1 svn-client svn-post-commit-hooks)
     6(use svnwiki-extensions-support srfi-40 html-stream stream-ext format-modular orders srfi-1 svn-client svn-post-commit-hooks svnwiki-javascript simple-profiler)
    77
    88(define (rating-render-bottom-span env)
     
    148148    (if (directory? (svnwiki-make-pathname path-in path))
    149149      path
    150       (svnwiki-make-pathname (butlast (string-split path "/"))))))
     150      (svnwiki-dirname path))))
    151151
    152152(define (svnwiki-rating-generate-best-content env)
     
    155155      (stream-map
    156156        (let ((dir-path (svnwiki-rating-dir-path env)))
    157           (lambda (file)
     157          (lambda (data)
    158158            (svnwiki-render-file-contents-included
    159               (environment env ((path (svnwiki-make-pathname dir-path file)))))))
     159              (environment env ((path (svnwiki-make-pathname dir-path (car data))))))))
    160160        (svnwiki-rating-get-best-posts env)))))
    161161
    162 ; Return the stream with the posts that should be included in the top
     162(define (update-top-list env)
     163  (let-from-environment env (path-in path path-out)
     164    (let ((path-list (svnwiki-make-pathname (list path "xsvnwiki-top"))))
     165      (svnwiki-report-progress env (svnwiki-translate env "Updating list of top rated pages: ~A~%") path)
     166      (write-file-with-tmp path-list "application/xml" path-out
     167        (->stream-char "<?xml version=\"1.0\"?>\n"
     168          (html-stream
     169            "<scores>"
     170            (stream-concatenate
     171              (stream-map
     172                (lambda (data)
     173                  (string->stream
     174                    (format #f "<item name='~A' file='~A' score='~A' votes='~A'/>"
     175                            (svnwiki-xml-escape (get-title path-in (svnwiki-make-pathname (svnwiki-dirname path) (first data)) (first data)))
     176                            (svnwiki-xml-escape (first data))
     177                            (second data)
     178                            (third data))))
     179                (svnwiki-rating-get-best-posts (environment env ((path (svnwiki-dirname path)))))))
     180            "</scores>"))))))
     181
     182(define (update-notify env)
     183  (let-from-environment env (path)
     184    (when (string=? (svnwiki-basename path) "xsvnwiki-rating")
     185      (update-top-list env))))
     186
     187(svnwiki-extension-define 'update-notify-recursive 'rating update-notify)
     188
     189; Return the stream with the posts that should be included in the top.  Each
     190; element of the stream is a list of the form (file score votes).
    163191
    164192(define (svnwiki-rating-get-best-posts env)
     
    167195      (if (directory? (svnwiki-make-pathname (list path-in dir-path) "xsvnwiki-rating"))
    168196        (stream-take-safe
    169           (stream-map
    170             car
    171             (stream-sort
    172               (stream-map
    173                 (lambda (file)
    174                   (receive (score votes)
    175                            (rating-compute
    176                              (environment env ((path (svnwiki-make-pathname (list dir-path "xsvnwiki-rating") file)))))
    177                     (list file score votes)))
    178                 (list->stream (directory (svnwiki-make-pathname (list path-in dir-path) "xsvnwiki-rating"))))
    179               (order (key> cadr) (key> caddr))))
     197          (stream-sort
     198            (stream-map
     199              (lambda (file)
     200                (receive (score votes)
     201                         (rating-compute
     202                           (environment env ((path (svnwiki-make-pathname (list dir-path "xsvnwiki-rating") file)))))
     203                  (list file score votes)))
     204              (list->stream (directory (svnwiki-make-pathname (list path-in dir-path) "xsvnwiki-rating"))))
     205            (order (key> cadr) (key> caddr)))
    180206          (string->number (get-props-parents-first "svnwiki:rating:best-count" path-in path "10")))
    181207        stream-null))))
     208
     209(profile-set! svnwiki-rating-get-best-posts)
    182210
    183211(define (rating-update-file env)
     
    213241        input)
    214242      (stream-length input))))
     243
     244(profile-set! rating-compute)
    215245
    216246(define (open-input-stream-rating env)
     
    276306(svnwiki-extension-define 'update-notify 'rating rating-update)
    277307(svnwiki-extension-define 'javascript 'rating rating-js-code)
     308
     309(define (rating-weblog-about-bottom env)
     310  (let-from-environment env (path-out-real)
     311    (svnwiki-javascript-show-top-list
     312      env
     313      "The following are the best rated posts in this weblog:"
     314      (make-link-url
     315        path-out-real
     316        (svnwiki-make-pathname
     317          (svnwiki-dirname (svnwiki-discuss->normal path-out-real))
     318          "xsvnwiki-rating/xsvnwiki-top")
     319        #f)
     320      "discuss")))
     321
     322(svnwiki-extension-define 'weblog-about-bottom-div 'discuss rating-weblog-about-bottom)
Note: See TracChangeset for help on using the changeset viewer.