Browse code
Reorg and fixed upsert
- Reorganized definitions to avoid warnings
- Fixed get-dao-for for rss-item to avoid binding rss-item's id slot if
not in db so that Postmodern just does the write thing on upsert
Showing 2 changed files
... | ... |
@@ -83,6 +83,36 @@ |
83 | 83 |
(pub-date :accessor rss-item-pub-date :initarg :pub-date) |
84 | 84 |
(source :accessor rss-item-source :initarg :source))) |
85 | 85 |
|
86 |
+@export |
|
87 |
+(defun make-rss-item (item) |
|
88 |
+ (lquery:initialize item) |
|
89 |
+ (flet ((dehtml (h) (plump:text (plump:parse h))) |
|
90 |
+ (get-category-names (it) ;;; TODO: simplify this---Ask Shinmera on IRC |
|
91 |
+ (if (not (equalp #() it)) |
|
92 |
+ (map 'vector |
|
93 |
+ (lambda (x) (plump:text (elt (plump:children x) 0))) |
|
94 |
+ it) |
|
95 |
+ #()))) |
|
96 |
+ (let* ((content-encoded (lquery:$ (children) (tag-name "content:encoded"))) |
|
97 |
+ |
|
98 |
+ (description-element (default-when content-encoded (emptyp content-encoded) |
|
99 |
+ (lquery:$ (children "description")))) |
|
100 |
+ |
|
101 |
+ (description-raw (normalize-html |
|
102 |
+ (default-when description-element (emptyp description-element) |
|
103 |
+ (extract-text "description")))) |
|
104 |
+ |
|
105 |
+ (description-munged (dehtml description-raw)) |
|
106 |
+ (category (get-category-names (lquery:$ "category")))) |
|
107 |
+ ;(enclosure) --- TODO: implement comment / enclosure handling |
|
108 |
+ |
|
109 |
+ (xml-text-bind (title link guid pub-date source comments) |
|
110 |
+ (make-instance-from-symbols 'rss-item |
|
111 |
+ item title link description-raw (description description-munged) |
|
112 |
+ category guid pub-date source comments))))) |
|
113 |
+ ;(setf (rss-item-enclosure result) enclosure) -- TODO: comment/enclosure . . . |
|
114 |
+ |
|
115 |
+ |
|
86 | 116 |
@export |
87 | 117 |
(defun make-rss-feed (feed) |
88 | 118 |
(lquery:initialize feed) |
... | ... |
@@ -146,15 +176,18 @@ |
146 | 176 |
(:method ((obj rss-item) &optional feed) |
147 | 177 |
(with-slots (title link description-raw guid pub-date source) obj |
148 | 178 |
(get-id-for-object (rss_item_store guid) guid |
149 |
- (make-instance-from-symbols 'rss_item_store id title link (description description-raw) |
|
150 |
- guid pub-date source feed (fetch-defaults t)))))) |
|
179 |
+ (let ((result (make-instance-from-symbols 'rss_item_store title link (description description-raw) |
|
180 |
+ guid pub-date source feed (fetch-defaults t)))) |
|
181 |
+ (unless (null id) |
|
182 |
+ (setf (ris-id result) id)) |
|
183 |
+ result))))) |
|
151 | 184 |
|
152 | 185 |
(define-condition blarg () ((text :initarg text))) |
153 | 186 |
@export |
154 | 187 |
(defun get-feed-from-dao (rss-feed) |
155 | 188 |
(let ((feed-dao (get-dao-for rss-feed))) |
156 | 189 |
(list feed-dao |
157 |
- (error 'blarg :text (format t "~a~%" rss-feed)) |
|
190 |
+ ;(error 'blarg :text (format t "~a~%" rss-feed)) |
|
158 | 191 |
(with-slots (items) rss-feed |
159 | 192 |
(iterate (for item in items) |
160 | 193 |
(collect (get-dao-for item (slot-value feed-dao 'id)))))))) |
... | ... |
@@ -167,7 +200,13 @@ |
167 | 200 |
(postmodern:upsert-dao feed) |
168 | 201 |
(mapcar #'postmodern:upsert-dao items)))) |
169 | 202 |
|
170 |
-; TODO: get rid of eval |
|
203 |
+@export |
|
204 |
+(defun store-item-dao (serialized-rss-item link) |
|
205 |
+ (apply #'postmodern:make-dao |
|
206 |
+ (list* 'rss_item_store :feed link |
|
207 |
+ (iterate (for (k . v) in-sequence serialized-rss-item) |
|
208 |
+ (appending (list k v)))))) |
|
209 |
+ |
|
171 | 210 |
@export |
172 | 211 |
(defun store-feed-dao (serialized-rss-feed &optional link) |
173 | 212 |
(declare (ignore link)) |
... | ... |
@@ -183,14 +222,6 @@ |
183 | 222 |
(slot-value rss_feed 'id))) |
184 | 223 |
rss_feed)) |
185 | 224 |
|
186 |
-@export |
|
187 |
-(defun store-item-dao (serialized-rss-item link) |
|
188 |
- (eval `(postmodern:make-dao |
|
189 |
- 'rss_item_store |
|
190 |
- :feed ,link |
|
191 |
- ,@(iterate (for (k . v) in-sequence serialized-rss-item) |
|
192 |
- (appending (list k v)))))) |
|
193 |
- |
|
194 | 225 |
(defun get-and-possibly-store-feed (rss-feed) |
195 | 226 |
"Given an rss-feed, return the db's feed-id, persisting it if it doesn't already exist." |
196 | 227 |
(postmodern:ensure-transaction |
... | ... |
@@ -260,35 +291,6 @@ |
260 | 291 |
html) |
261 | 292 |
ss))) |
262 | 293 |
|
263 |
-@export |
|
264 |
-(defun make-rss-item (item) |
|
265 |
- (lquery:initialize item) |
|
266 |
- (flet ((dehtml (h) (plump:text (plump:parse h))) |
|
267 |
- (get-category-names (it) ;;; TODO: simplify this---Ask Shinmera on IRC |
|
268 |
- (if (not (equalp #() it)) |
|
269 |
- (map 'vector |
|
270 |
- (lambda (x) (plump:text (elt (plump:children x) 0))) |
|
271 |
- it) |
|
272 |
- #()))) |
|
273 |
- (let* ((content-encoded (lquery:$ (children) (tag-name "content:encoded"))) |
|
274 |
- |
|
275 |
- (description-element (default-when content-encoded (emptyp content-encoded) |
|
276 |
- (lquery:$ (children "description")))) |
|
277 |
- |
|
278 |
- (description-raw (normalize-html |
|
279 |
- (default-when description-element (emptyp description-element) |
|
280 |
- (extract-text "description")))) |
|
281 |
- |
|
282 |
- (description-munged (dehtml description-raw)) |
|
283 |
- (category (get-category-names (lquery:$ "category")))) |
|
284 |
- ;(enclosure) --- TODO: implement comment / enclosure handling |
|
285 |
- |
|
286 |
- (xml-text-bind (title link guid pub-date source comments) |
|
287 |
- (make-instance-from-symbols 'rss-item |
|
288 |
- item title link description-raw (description description-munged) |
|
289 |
- category guid pub-date source comments))))) |
|
290 |
- ;(setf (rss-item-enclosure result) enclosure) -- TODO: comment/enclosure . . . |
|
291 |
- |
|
292 | 294 |
|
293 | 295 |
; \o/ |
294 | 296 |
; | Arrr |