Index: openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql,v
diff -u -r1.6 -r1.7
--- openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql	13 Nov 2017 15:22:26 -0000	1.6
+++ openacs-4/packages/forums/sql/postgresql/forums-reading-info-create.sql	3 Sep 2024 15:37:38 -0000	1.7
@@ -15,7 +15,7 @@
     forum_id        integer
                     constraint forum_read_forum_id_fk
                     references forums_forums (forum_id)
-                    on delete cascade                    
+                    on delete cascade
                     constraint forums_read_forum_id_nn
                     not null,
     constraint forums_reading_info_pk primary key (root_message_id,user_id)
@@ -24,6 +24,7 @@
 create index forums_reading_info_user_index on forums_reading_info (user_id);
 create index forums_reading_info_forum_message_index on forums_reading_info (root_message_id);
 create index forums_reading_info_forum_forum_index on forums_reading_info (forum_id);
+create index forums_reading_info_user_id_root_message_id_idx on forums_reading_info(user_id,root_message_id);
 
 create or replace view forums_reading_info_user as
    select forum_id,
@@ -46,7 +47,7 @@
 ) RETURNS integer AS $$
 DECLARE
 BEGIN
-    delete from forums_reading_info 
+    delete from forums_reading_info
      where root_message_id = p_message_id;
     return 0;
 END;
@@ -68,7 +69,7 @@
 DECLARE
    v_message_id integer;
 BEGIN
-    for v_message_id in 
+    for v_message_id in
      select message_id
        from forums_messages_approved m
       where forum_id = p_forum_id
@@ -119,7 +120,7 @@
                 p_user_id,
                 (select forum_id from forums_messages
                   where message_id = p_root_message_id)
-             );   
+             );
     end if;
 
     return 0;
@@ -145,21 +146,20 @@
    select root_message_id from forums_forums
     where forum_id = (select forum_id from forums_messages
                        where message_id = p_source_message_id) into v_source_root_message_id;
-   
+
    -- for all users that have read target, but not the source, remove
    -- target_info
    delete from forums_reading_info i
     where root_message_id = p_target_message_id
       and not exists (select 1 from forums_reading_info
                        where root_message_id = v_source_root_message_id
                          and user_id = i.user_id);
-                         
+
    -- for all users that have read source, remove reading info four
    -- source message since it no longer is root_message_id
    delete from forums_reading_info
     where root_message_id = p_source_message_id;
-    
+
     return 1;
 END;
 $$ LANGUAGE plpgsql;
-
