From 9d4d0cecdbe91d7aa82a1baf010c864f2d552ebe Mon Sep 17 00:00:00 2001 From: zhitomirskiyi Date: Mon, 10 Jan 2011 13:22:34 -0800 Subject: [PATCH] wip --- app/models/notification.rb | 3 +- app/models/person.rb | 1 + ...0110023610_notification_multiple_people.rb | 34 +++++++++++++++---- db/schema.rb | 16 ++------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/models/notification.rb b/app/models/notification.rb index dfe54a962..e07ec0bf5 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -7,7 +7,8 @@ class Notification < ActiveRecord::Base include Diaspora::Socketable belongs_to :recipient, :class_name => 'User' - has_many :actors, :class_name => 'Person', :through => :notification_actors + has_many :notification_actors + has_many :actors, :class_name => 'Person', :through => :notification_actors, :source => :person belongs_to :target, :polymorphic => true def self.for(recipient, opts={}) diff --git a/app/models/person.rb b/app/models/person.rb index 4f99c3c5d..d75191d04 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -29,6 +29,7 @@ class Person < ActiveRecord::Base belongs_to :owner, :class_name => 'User' + has_many :notification_actors has_many :notifications, :through => :notification_actors before_destroy :remove_all_traces diff --git a/db/migrate/20110110023610_notification_multiple_people.rb b/db/migrate/20110110023610_notification_multiple_people.rb index 42f6c0382..ed52bbba6 100644 --- a/db/migrate/20110110023610_notification_multiple_people.rb +++ b/db/migrate/20110110023610_notification_multiple_people.rb @@ -1,23 +1,45 @@ class NotificationMultiplePeople < ActiveRecord::Migration def self.up create_table :notification_actors do |t| - t.integer :notifications_id + t.integer :notification_id t.integer :person_id t.timestamps end - add_index :notification_actors, :notifications_id - add_index :notification_actors, [:notifications_id, :person_id] , :unique => true + add_index :notification_actors, :notification_id + add_index :notification_actors, [:notification_id, :person_id] , :unique => true add_index :notification_actors, :person_id ## if i am not mistaken we don't need this one because we won't query person.notifications - execute "INSERT INTO notification_actors (id, person_id) " + + execute "INSERT INTO notification_actors (notification_id, person_id) " + " SELECT id , actor_id " + " FROM notifications" + + #TODO in sql + #bump up target to status message id if comment_on_post, also_commented + ['comment_on_post', 'also_commented'].each do |type| + + Notification.where(:type => 'comment_on_post').all.each{|n| + n.target_id => Comment.find(n.target_id).post} + + #for each user + all = Notification.where(:type => 'comment_on_post', :user => user).all + first = all.first + all[1..all.length-1].each{ |a| + first << a.notification_actors + a.delete + } + + end + + # all notification of same type with the same + + + remove_column :notification, :actor_id end def self.down - remove_index :notification_actors, :notifications_id - remove_index :notification_actors, [:notifications_id, :person_id] + remove_index :notification_actors, :notification_id + remove_index :notification_actors, [:notification_id, :person_id] remove_index :notification_actors, :person_id drop_table :notification_actors diff --git a/db/schema.rb b/db/schema.rb index 59135130a..2fa0551f1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -47,7 +47,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.text "youtube_titles" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "comments", ["guid"], :name => "index_comments_on_guid", :unique => true @@ -61,7 +60,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.boolean "pending", :default => true, :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "contacts", ["mongo_id"], :name => "index_contacts_on_mongo_id" @@ -86,7 +84,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.integer "aspect_id" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "invitations", ["aspect_id"], :name => "index_invitations_on_aspect_id" @@ -294,14 +291,14 @@ ActiveRecord::Schema.define(:version => 20110127000953) do add_index "mongo_users", ["mongo_id"], :name => "index_mongo_users_on_mongo_id", :unique => true create_table "notification_actors", :force => true do |t| - t.integer "notifications_id" + t.integer "notification_id" t.integer "person_id" t.datetime "created_at" t.datetime "updated_at" end - add_index "notification_actors", ["notifications_id", "person_id"], :name => "index_notification_actors_on_notifications_id_and_person_id", :unique => true - add_index "notification_actors", ["notifications_id"], :name => "index_notification_actors_on_notifications_id" + add_index "notification_actors", ["notification_id", "person_id"], :name => "index_notification_actors_on_notification_id_and_person_id", :unique => true + add_index "notification_actors", ["notification_id"], :name => "index_notification_actors_on_notification_id" add_index "notification_actors", ["person_id"], :name => "index_notification_actors_on_person_id" create_table "notifications", :force => true do |t| @@ -313,7 +310,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.boolean "unread", :default => true, :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "notifications", ["mongo_id"], :name => "index_notifications_on_mongo_id" @@ -329,7 +325,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.integer "owner_id" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "people", ["diaspora_handle"], :name => "index_people_on_diaspora_handle", :unique => true @@ -365,7 +360,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.text "youtube_titles" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "posts", ["guid"], :name => "index_posts_on_guid" @@ -390,7 +384,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.integer "person_id", :null => false t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "profiles", ["first_name", "last_name", "searchable"], :name => "index_profiles_on_first_name_and_last_name_and_searchable" @@ -405,7 +398,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.integer "aspect_id" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" end add_index "requests", ["mongo_id"], :name => "index_requests_on_mongo_id" @@ -422,8 +414,6 @@ ActiveRecord::Schema.define(:version => 20110127000953) do t.string "nickname" t.datetime "created_at" t.datetime "updated_at" - t.string "mongo_id" - t.string "user_mongo_id" end add_index "services", ["mongo_id"], :name => "index_services_on_mongo_id"