Index: openacs-4/packages/views/sql/postgresql/views-datamodel.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/views/sql/postgresql/views-datamodel.sql,v diff -u -r1.1 -r1.1.6.1 --- openacs-4/packages/views/sql/postgresql/views-datamodel.sql 20 May 2004 13:01:30 -0000 1.1 +++ openacs-4/packages/views/sql/postgresql/views-datamodel.sql 21 Jul 2006 11:32:44 -0000 1.1.6.1 @@ -12,26 +12,26 @@ -- License. Full text of the license is available from the GNU Project: -- http://www.fsf.org/copyleft/gpl.html -create table views ( +create table views_views ( object_id integer - constraint views_object_id_fk + constraint views_views_object_id_fk references acs_objects(object_id) on delete cascade constraint views_object_id_nn not null, viewer_id integer - constraint views_owner_id_fk + constraint views_views_owner_id_fk references parties(party_id) on delete cascade - constraint views_viewer_id_nn + constraint views_views_viewer_id_nn not null, - views integer default 1, + views_count integer default 1, last_viewed timestamptz default now(), - constraint views_pk + constraint views_views_pk primary key (object_id, viewer_id) ); -create unique index views_viewer_idx on views(viewer_id, object_id); +create unique index views_views_viewer_idx on views_views(viewer_id, object_id); -comment on table views is ' +comment on table views_views is ' a simple count of how many times an object is viewed. '; @@ -43,7 +43,7 @@ not null constraint view_aggregatess_pk primary key, - views integer default 1, + views_count integer default 1, unique_views integer default 1, last_viewed timestamptz default now() ); @@ -53,11 +53,3 @@ trigger maintained by updates on views. '; - - - - - - - - Index: openacs-4/packages/views/sql/postgresql/views-drop.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/views/sql/postgresql/views-drop.sql,v diff -u -r1.1 -r1.1.6.1 --- openacs-4/packages/views/sql/postgresql/views-drop.sql 20 May 2004 13:01:30 -0000 1.1 +++ openacs-4/packages/views/sql/postgresql/views-drop.sql 21 Jul 2006 11:32:44 -0000 1.1.6.1 @@ -12,7 +12,7 @@ select drop_package('views'); drop table view_aggregates; -drop table views; -drop function views_upd_tr(); -drop function views_ins_tr(); +drop table views_views; +drop function views_views_upd_tr(); +drop function views_views_ins_tr(); Index: openacs-4/packages/views/sql/postgresql/views-procs.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/views/sql/postgresql/views-procs.sql,v diff -u -r1.1 -r1.1.6.1 --- openacs-4/packages/views/sql/postgresql/views-procs.sql 20 May 2004 13:01:30 -0000 1.1 +++ openacs-4/packages/views/sql/postgresql/views-procs.sql 21 Jul 2006 11:32:44 -0000 1.1.6.1 @@ -16,17 +16,17 @@ declare p_object_id alias for $1; p_viewer_id alias for $2; - v_views views.views%TYPE; + v_views views_views.views_count%TYPE; begin - select views into v_views from views where object_id = p_object_id and viewer_id = p_viewer_id; + select views_count into v_views from views_views where object_id = p_object_id and viewer_id = p_viewer_id; if v_views is null then - INSERT into views(object_id,viewer_id) + INSERT into views_views(object_id,viewer_id) VALUES (p_object_id, p_viewer_id); v_views := 0; else - UPDATE views - SET views = views + 1, last_viewed = now() + UPDATE views_views + SET views_count = views_count + 1, last_viewed = now() WHERE object_id = p_object_id and viewer_id = p_viewer_id; end if; Index: openacs-4/packages/views/sql/postgresql/views-triggers.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/views/sql/postgresql/views-triggers.sql,v diff -u -r1.1 -r1.1.6.1 --- openacs-4/packages/views/sql/postgresql/views-triggers.sql 20 May 2004 13:01:30 -0000 1.1 +++ openacs-4/packages/views/sql/postgresql/views-triggers.sql 21 Jul 2006 11:32:44 -0000 1.1.6.1 @@ -12,37 +12,37 @@ -- License. Full text of the license is available from the GNU Project: -- http://www.fsf.org/copyleft/gpl.html -create function views_ins_tr () returns opaque as ' +create function views_views_ins_tr () returns opaque as ' begin if not exists (select 1 from view_aggregates where object_id = new.object_id) then - INSERT INTO view_aggregates (object_id,views,unique_views,last_viewed) + INSERT INTO view_aggregates (object_id,views_count,unique_views,last_viewed) VALUES (new.object_id,1,1,now()); else UPDATE view_aggregates - SET views = views + 1, unique_views = unique_views + 1, last_viewed = now() + SET views_count = views_count + 1, unique_views = unique_views + 1, last_viewed = now() WHERE object_id = new.object_id; end if; return new; end;' language 'plpgsql'; -create trigger views_ins_tr -after insert on views +create trigger views_views_ins_tr +after insert on views_views for each row -execute procedure views_ins_tr(); +execute procedure views_views_ins_tr(); -create function views_upd_tr () returns opaque as ' +create function views_views_upd_tr () returns opaque as ' begin UPDATE view_aggregates - SET views = views + 1, last_viewed = now() + SET views_count = views_count + 1, last_viewed = now() WHERE object_id = new.object_id; return new; end;' language 'plpgsql'; -create trigger views_upd_tr -after update on views +create trigger views_views_upd_tr +after update on views_views for each row -execute procedure views_upd_tr(); +execute procedure views_views_upd_tr(); -- XXXJCD: Should there be a delete trigger?