Commits

Anonymous committed 6088875

Fixed long-standing bug with determing whether a template had expired. Problem was bad set of class definitions, now fixed. In fixing, also moved to using local-time for all time calculations (including file times) for consistency.

Comments (0)

Files changed (4)

 	       "drakma"
 	       "parenscript"
 	       "cl-ppcre"
+	       "local-time"
 
 	       ; project packages
                )

package-hh-web-tags.lisp

 
 (defpackage :hh-web
   (:nicknames :hh-web)
-  (:use :cl :sb-mop :cl-ppcre)
+  (:use :cl :sb-mop :cl-ppcre :local-time)
   (:export
     
     ;; Exported symbols go here

taglibraries.lisp

   return the tag source as a stream or string"
   )
 
-(defvar *minimum-tag-library-stale-time* 1.0
+(defvar *minimum-tag-library-stale-time* 1
   "Minimum time in seconds for which a tag library must remain stale (e.g. not expire)
    before reloading from its source"
 )
     :accessor tag-library-provider
     )
    (modified-time
-    :initform (get-internal-real-time)
+    :initform (now)
     :accessor modified-time-of
     )
    (package
 
 (defgeneric tag-library-stalep (library)
   (:method ( (library tag-library) )
-    (>  (- (get-internal-real-time)
-	   (modified-time-of library)
-	   )
-	(* *minimum-tag-library-stale-time* 
-	   internal-time-units-per-second
-	   )
-	)
+    (timestamp> (now) 
+       (timestamp+ (modified-time-of library) *minimum-tag-library-stale-time* :sec)
+       )
     )
   )
 
   )
 
 (defmethod tag-library-expiredp ( (library tag-library) )
-    (if (tag-library-stalep library)
-	t
-	(or (provider-tag-library-expiredp library (tag-library-provider library) )
-	    (find-if #'(lambda (library-name) 
-			 (let (
-			       (library (find-cached-tag-library library-name))
-			       )
-			   (if library
-			       (tag-library-expiredp (find-cached-tag-library library-name) )
-			       t
-			       )
+  (when (tag-library-stalep library)
+    (or (provider-tag-library-expiredp library (tag-library-provider library) )
+	(find-if #'(lambda (library-name) 
+		     (let (
+			   (library (find-cached-tag-library library-name))
 			   )
-			 )
-		     (tag-libraries-used library )
+		       (if library
+			   (tag-library-expiredp (find-cached-tag-library library-name) )
+			   t
+			   )
+		       )
 		     )
-	    )
+		 (tag-libraries-used library )
+		 )
 	)
     )
+  )
 
 ;; -------- Folder provider ---------------------
 ;; 
 
 (defgeneric tag-library-file-modified-time (library-name provider)
   (:method (library-name (provider folder-tag-library-provider) )
-    ;; not sure why, but mtime seems about 70 years off of the time reported
-    ;; by get-internal-real-time--probably an OS-specific behavior (Mac in this case), so will need to adjust
-    ;; later for other platforms (e.g., Linux)
     (let (
 	  (full-path (tag-library-full-path library-name provider) )
 	  )
-      (multiple-value-bind (second minute hour date month year day-of-week dst tz)
-	  (decode-universal-time (sb-posix:stat-mtime (sb-posix:stat full-path)) )
-	(encode-universal-time second minute hour date month (+ 70 year) )
-	)
+      (unix-to-timestamp (sb-posix:stat-mtime (sb-posix:stat full-path)) )
       )
     )
   )
 ; -- Implementation of base tag-library-provider functions
 
 (defmethod provider-tag-library-expiredp (library (provider folder-tag-library-provider) )
-  (>  (tag-library-file-modified-time (tag-library-name library) provider)
+  (timestamp>  (tag-library-file-modified-time (tag-library-name library) provider)
 	(modified-time-of library)
 	)
   )
    a definition is being read"
   )
 
-(defvar *minimum-template-stale-time* 1.0
+(defvar *minimum-template-stale-time* 1
   "Minimum time in seconds for which a template must remain stale (e.g. not expire,
    before reloading from its source"
 )
     :accessor tag-libraries-used
     )
    (modified-time
-    :initform (get-internal-real-time)
+    :initform (now)
     :accessor modified-time-of
     )
    (package
 (defgeneric template-stalep (tmpl)
   (:method ( (tmpl template) )
     (if (definition-of tmpl)
-	(>  (- (get-internal-real-time)
-	       (modified-time-of tmpl)
-	       )
-	    (* *minimum-template-stale-time* 
-	       internal-time-units-per-second
-	       )
-	    )
+	(timestamp> (now) 
+	   (timestamp+ (modified-time-of tmpl) *minimum-template-stale-time* :sec)
+	   )
 	t
 	)
     )
   (:method ( (tmpl template) )
     (find-if #'(lambda (library-name) 
 		 (let (
-		       (library (hh-web::find-cached-tag-library library-name))
+		       (library (find-cached-tag-library library-name))
 		       )
 		   (if library
-		       (hh-web::tag-library-expiredp (hh-web::find-cached-tag-library library-name) )
+		       (tag-library-expiredp (hh-web::find-cached-tag-library library-name) )
 		       t
 		       )
 		   )
 
 (defgeneric template-expiredp (tmpl)
   (:method ( (tmpl template) )
-    (if (template-stalep tmpl)
-	t
-	(or (template-tags-expiredp tmpl)
-	    (provider-template-expiredp tmpl (template-provider tmpl) )
-	    )
-	)
+    (when (template-stalep tmpl)
+      (or (template-tags-expiredp tmpl)
+	  (provider-template-expiredp tmpl (template-provider tmpl) )
+	  )
+      )
     )
   )
 
   "Safely a cached template, typically for reloading"
   ;; remove the template from the cache
   (remhash template-path *template-cache*)
-  ;; also, delete the template's package...could cluter up the runtime
+  ;; also, delete the template's package...could clutter up the runtime
   (when (template-package cached-template)
     (delete-package (template-package cached-template))
     )
 ;;  Generalized definitions designed to aid any template provider
 ;;  that serves templates from a filesystem
 
-(defclass file-based-template-provider ()
+(defclass file-based-template-provider (template-provider)
   (
    )
   (:documentation "Generalized type for providers serving templates from the filesystem")
 
 (defgeneric template-file-modified-time (template-path provider)
   (:method (template-path (provider file-based-template-provider) )
-    ;; not sure why, but mtime seems about 70 years off of the time reported
-    ;; by get-internal-real-time--probably an OS-specific behavior (Mac in this case), so will need to adjust
-    ;; later for other platforms (e.g., Linux)
     (let (
 	  (full-path (template-full-path template-path provider) )
 	  )
-      (multiple-value-bind (second minute hour date month year day-of-week dst tz)
-	  (decode-universal-time (sb-posix:stat-mtime (sb-posix:stat full-path)) )
-	(encode-universal-time second minute hour date month (+ 70 year) )
-	)
+      (unix-to-timestamp (sb-posix:stat-mtime (sb-posix:stat full-path)) )
       )
     )
   )
   (let (
 	(full-path (template-full-path (template-path *template*) provider) )
 	)
-    (>  (template-file-modified-time full-path provider)
-	(modified-time-of *template*)
-	)
+    (timestamp> (template-file-modified-time full-path provider)
+		(modified-time-of *template*)
+		)
     )
   )
 
 ;;  provides templates in individual files of a specified 
 ;;  folder on the filesystem
 
-(defclass folder-template-provider (template-provider file-based-template-provider)
+(defclass folder-template-provider (file-based-template-provider)
   (
    (folder
     :initarg :folder
 ;;  templates in individual files from any of those locations
 ;;
 
-(defclass asdf-system-provider (template-provider file-based-template-provider)
+(defclass asdf-system-provider (file-based-template-provider)
   (
    (system
     :initform nil
 	(full-path (template-full-path (template-path *template*) provider) )
 	)
     (when (probe-file full-path) ;; if file does not exist, no point in declaring it expired--can't reload anyway
-      (>  (template-file-modified-time full-path provider)
-	  (modified-time-of *template*)
-	  )
+      (timestamp> (template-file-modified-time full-path provider)
+		  (modified-time-of *template*)
+		  )
       )
     )
   )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.