From 7dd6716fc596e7d2e8501a84aab5d941edb661b4 Mon Sep 17 00:00:00 2001 From: saturn Date: Thu, 9 May 2024 14:40:13 -0500 Subject: [PATCH] Request more items beyond limit to work around LW weirdness. --- lw2.lisp | 14 +++++++------- src/backend.lisp | 15 ++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lw2.lisp b/lw2.lisp index b4d2c74b..fda79c16 100644 --- a/lw2.lisp +++ b/lw2.lisp @@ -1004,7 +1004,7 @@ (when (eq view :new) (redirect (replace-query-params (hunchentoot:request-uri*) "view" "all" "all" nil) :type :permanent) (return)) (component-value-bind ((sort-string sort-widget)) (multiple-value-bind (posts total last-modified) - (get-posts-index :view (string-downcase view) :before before :after after :offset offset :limit (1+ limit) :sort sort-string :karma-threshold karma-threshold) + (get-posts-index :view (string-downcase view) :before before :after after :offset offset :limit (+ 20 limit) :sort sort-string :karma-threshold karma-threshold) (handle-last-modified last-modified) (let ((page-title (format nil "~@(~A posts~)" view))) (renderer () @@ -1638,15 +1638,15 @@ (multiple-value-bind (items total last-modified) (case show (:posts - (get-user-page-items user-id :posts :offset offset :limit (+ 1 (user-pref :items-per-page)) :sort-type sort-type)) + (get-user-page-items user-id :posts :offset offset :limit (+ 20 (user-pref :items-per-page)) :sort-type sort-type)) (:comments - (get-user-page-items user-id :comments :offset offset :limit (+ 1 (user-pref :items-per-page)) :sort-type sort-type)) + (get-user-page-items user-id :comments :offset offset :limit (+ 20 (user-pref :items-per-page)) :sort-type sort-type)) (:drafts - (get-user-page-items user-id :posts :drafts t :offset offset :limit (+ 1 (user-pref :items-per-page)) :auth-token (hunchentoot:cookie-in "lw2-auth-token"))) + (get-user-page-items user-id :posts :drafts t :offset offset :limit (+ 20 (user-pref :items-per-page)) :auth-token (hunchentoot:cookie-in "lw2-auth-token"))) (:conversations (let ((conversations (lw2-graphql-query (lw2-query-string :conversation :list - (alist :view "userConversations" :limit (+ 1 (user-pref :items-per-page)) :offset offset :user-id user-id) + (alist :view "userConversations" :limit (+ 20 (user-pref :items-per-page)) :offset offset :user-id user-id) :fields '(:--id :created-at :title (:participants :display-name :slug) :----typename)) :auth-token (hunchentoot:cookie-in "lw2-auth-token")))) (lw2-graphql-query-map @@ -1705,7 +1705,7 @@ (lw2-not-allowed-error

This may mean your login token has expired or become invalid. You can try logging in again.

))) (t - (get-user-page-items user-id :both :offset offset :limit (+ 1 (user-pref :items-per-page)) :sort-type sort-type))) + (get-user-page-items user-id :both :offset offset :limit (+ 20 (user-pref :items-per-page)) :sort-type sort-type))) (handle-last-modified last-modified) (let ((with-next (> (length items) (+ (if (eq show :all) offset 0) (user-pref :items-per-page)))) (interleave (if (eq show :all) (comment-post-interleave items :limit (user-pref :items-per-page) :offset (if (eq show :all) offset nil) :sort-by sort-type) (firstn items (user-pref :items-per-page))))) ; this destructively sorts items @@ -2087,7 +2087,7 @@ (format out-stream "")))) (multiple-value-bind (posts total) (lw2-graphql-query (lw2-query-string :post :list - (alist :view (if day "new" "top") :limit 51 :offset offset + (alist :view (if day "new" "top") :limit (+ 20 50) :offset offset :after (if (and year (not day)) (format nil "~A-~A-~A" (or year earliest-year) (or month 1) (or day 1))) :before (if year (format nil "~A-~A-~A" (or year current-year) (or month 12) (or day (local-time:days-in-month (or month 12) (or year current-year)))))))) diff --git a/src/backend.lisp b/src/backend.lisp index e1331d8c..b38b0140 100644 --- a/src/backend.lisp +++ b/src/backend.lisp @@ -590,7 +590,7 @@ (t () (get-cached-result))) (query-and-put)))))) -(define-backend-function get-posts-index-query-terms (&key view (sort "new") (limit 21) offset before after karma-threshold &allow-other-keys) +(define-backend-function get-posts-index-query-terms (&key view (sort "new") (limit 40) offset before after karma-threshold &allow-other-keys) (backend-lw2-legacy (let ((sort-key (alexandria:switch (sort :test #'string=) ("new" "new") @@ -609,7 +609,8 @@ ("reviews" (alist :view "reviews2019")) (t (values (alist :sorted-by sort-key :filter "frontpage") - (if (not (or (string/= sort "new") (/= limit 21) offset before after karma-threshold)) "new-not-meta")))) + (if (not (or (string/= sort "new") (/= limit 40) offset before after karma-threshold)) + "new-not-meta")))) (let ((terms (alist-without-null* :before before :after after @@ -637,7 +638,7 @@ (values (lw2-query-string :post :list query-terms) cache-key)))) -(define-backend-function get-posts-index (&rest args &key (limit 21) offset &allow-other-keys) +(define-backend-function get-posts-index (&rest args &key (limit 40) offset &allow-other-keys) (backend-lw2-legacy (declare (dynamic-extent args)) (multiple-value-bind (query-string cache-key) @@ -651,7 +652,7 @@ (subseq* result offset (+ limit offset)) result)))))) -(define-backend-operation get-posts-index backend-lw2-tags :around (&rest args &key hide-tags offset (limit 21) &allow-other-keys) +(define-backend-operation get-posts-index backend-lw2-tags :around (&rest args &key hide-tags offset (limit 40) &allow-other-keys) ;; Workaround for https://github.com/LessWrong2/Lesswrong2/issues/3099 (declare (dynamic-extent args)) (if hide-tags @@ -972,7 +973,7 @@ (user-deleted user-id deleted)))) result))) -(define-backend-function get-notifications (&key user-id (offset 0) (limit 21) auth-token) +(define-backend-function get-notifications (&key user-id (offset 0) (limit 40) auth-token) (backend-lw2-legacy (lw2-graphql-query (lw2-query-string :notification :list (alist* :user-id user-id :limit limit :offset offset *notifications-base-terms*) @@ -1024,7 +1025,7 @@ (backend-lw2-legacy (cache-get "comment-reply-by-user" (concatenate 'string comment-id " " user-id)))) -(define-backend-function get-user-page-items (user-id request-type &key (offset 0) (limit 21) (sort-type :date) drafts +(define-backend-function get-user-page-items (user-id request-type &key (offset 0) (limit 40) (sort-type :date) drafts (revalidate *revalidate-default*) (force-revalidate *force-revalidate-default*) auth-token) (backend-lw2-legacy (multiple-value-bind (real-offset real-limit) (if (eq request-type :both) @@ -1032,7 +1033,7 @@ (values offset limit)) (let* ((cache-database (when (and (eq request-type :both) (or (not offset) (= offset 0)) - (= limit 21) + (= limit 40) (eq sort-type :date) (not drafts) (not auth-token)) -- 2.11.4.GIT