diff --git a/lib/PZ/Schema/Result/Shortcut.pm b/lib/PZ/Schema/Result/Shortcut.pm index 11d302279d418a06ae37674fe7081bb48f1a8313..372b6f8bce544fee9a38435f980b87d41c6ebf33 100644 --- a/lib/PZ/Schema/Result/Shortcut.pm +++ b/lib/PZ/Schema/Result/Shortcut.pm @@ -41,5 +41,16 @@ __PACKAGE__->has_many( log_items => 'PZ::Schema::Result::Log', { 'foreign.shortcut_id' => 'self.id', }, ); + +__PACKAGE__->has_many( + stat_hourly_items => 'PZ::Schema::Result::StatHourly', + { 'foreign.shortcut_id' => 'self.id', }, +); + +__PACKAGE__->has_many( + stat_dayly_items => 'PZ::Schema::Result::StatDayly', + { 'foreign.shortcut_id' => 'self.id', }, +); + 1; diff --git a/lib/PZ/Schema/Result/StatDaily.pm b/lib/PZ/Schema/Result/StatDaily.pm new file mode 100644 index 0000000000000000000000000000000000000000..3eb6f6175b95331fa8789fae25aec0d5e608850d --- /dev/null +++ b/lib/PZ/Schema/Result/StatDaily.pm @@ -0,0 +1,22 @@ +package PZ::Schema::Result::StatDaily; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +our $VERSION = 1; + +__PACKAGE__->table('stat_daily'); + +__PACKAGE__->add_columns( + qw( + shortcut_id + period + count + ), +); + +__PACKAGE__->set_primary_key('shortcut_id', 'period'); + +1; diff --git a/lib/PZ/Schema/Result/StatHourly.pm b/lib/PZ/Schema/Result/StatHourly.pm new file mode 100644 index 0000000000000000000000000000000000000000..e73c2061e750779f3223c259bc486a2eb5a6f73b --- /dev/null +++ b/lib/PZ/Schema/Result/StatHourly.pm @@ -0,0 +1,22 @@ +package PZ::Schema::Result::StatHourly; + +use strict; +use warnings; + +use base 'DBIx::Class::Core'; + +our $VERSION = 1; + +__PACKAGE__->table('stat_hourly'); + +__PACKAGE__->add_columns( + qw( + shortcut_id + period + count + ), +); + +__PACKAGE__->set_primary_key('shortcut_id', 'period'); + +1; diff --git a/sql/migrations.sql b/sql/migrations.sql index 9dcaaffecd605038024d6fba7b6005501df0b506..0a31e8d1461c00eab25afe84321132078ff4e22d 100644 --- a/sql/migrations.sql +++ b/sql/migrations.sql @@ -50,3 +50,24 @@ alter table "log" add column "ua" text; -- 4 up alter table "log" add column "referrer" text; + +-- 5 up +create view "stat_hourly" as +select + "shortcut_id", + date_trunc('hour', "time") as "period", + count(*) +from "log" + group by "shortcut_id", date_trunc('hour', "time") + order by date_trunc('hour', "time") +; + +create view "stat_daily" as +select + "shortcut_id", + date_trunc('day', "time") as "period", + count(*) +from "log" + group by "shortcut_id", date_trunc('day', "time") + order by date_trunc('day', "time") +;