From 45a56fcf11ca34f602cfdf9c8b8455f7df655faa Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 13 Jun 2020 13:02:23 +0200 Subject: [PATCH] - prevent adding duplicate entries in +table-pagination-status+ This could happened when concurrent fetching messages command was launched from the user. --- src/db.lisp | 19 +++++++++++++++---- src/package.lisp | 1 + src/program-events.lisp | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/db.lisp b/src/db.lisp index 0aab07e..d7b3740 100644 --- a/src/db.lisp +++ b/src/db.lisp @@ -1936,10 +1936,21 @@ to `timeline' , `folder' and possibly `account-id', older than (defun first-pagination-status-id-timeline-folder (timeline folder) (first-status-id-timeline-folder-table timeline folder :pagination-status)) -(defun add-to-pagination-status (status-id folder timeline) - (query (make-insert +table-pagination-status+ - (:status-id :folder :timeline) - (status-id folder timeline)))) +(defun find-pagination-status (status-id folder timeline) + (fetch-single (select :* + (from +table-pagination-status+) + (where (:and (:= :status-id status-id) + (:= :folder folder) + (:= :timeline timeline)))))) + +(defun add-to-pagination-status (status-id folder timeline &key (ensure-no-duplicates nil)) + (let ((no-duplicate-p (if ensure-no-duplicates + (not (find-pagination-status status-id folder timeline)) + t))) + (when no-duplicate-p + (query (make-insert +table-pagination-status+ + (:status-id :folder :timeline) + (status-id folder timeline)))))) (defun remove-pagination-status (folder timeline) "Removes all the pagination data (i.e. all columns from table diff --git a/src/package.lisp b/src/package.lisp index 3f3d9c9..daf8888 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -761,6 +761,7 @@ :first-ignored-status-id-timeline-folder :last-pagination-status-id-timeline-folder :first-pagination-status-id-timeline-folder + :find-pagination-status :add-to-pagination-status :remove-pagination-status :count-status-marked-to-delete diff --git a/src/program-events.lisp b/src/program-events.lisp index f4a8655..712347a 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -860,7 +860,7 @@ (with-accessors ((status-id status-id) (timeline timeline) (folder folder)) object - (db:add-to-pagination-status status-id folder timeline))) + (db:add-to-pagination-status status-id folder timeline :ensure-no-duplicates t))) (defclass poll-vote-event (program-event) ((poll-id