Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: move data to separate tables (#52)
We are trying to avoid custom tables. Changes: CategoryCustomField -> DiscourseVoting::CategorySetting # contains infromation if voting is enabled for category UserCustomField -> DiscourseVoting::Vote # user's votes TopicCustomField -> DiscourseVoting::VoteCounter # cache count for topics
- Loading branch information
Showing
22 changed files
with
527 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseVoting | ||
class CategorySetting < ActiveRecord::Base | ||
self.table_name = 'discourse_voting_category_settings' | ||
|
||
belongs_to :category | ||
|
||
before_create :unarchive_votes | ||
before_destroy :archive_votes | ||
after_save :reset_voting_cache | ||
|
||
def unarchive_votes | ||
DB.exec(<<~SQL, { category_id: self.category_id }) | ||
UPDATE discourse_voting_votes | ||
SET archive=false | ||
FROM topics | ||
WHERE topics.category_id = :category_id | ||
AND topics.deleted_at is NULL | ||
AND NOT topics.closed | ||
AND NOT topics.archived | ||
AND discourse_voting_votes.topic_id = topics.id | ||
SQL | ||
end | ||
|
||
def archive_votes | ||
DB.exec(<<~SQL, { category_id: self.category_id }) | ||
UPDATE discourse_voting_votes | ||
SET archive=true | ||
FROM topics | ||
WHERE topics.category_id = :category_id | ||
AND discourse_voting_votes.topic_id = topics.id | ||
SQL | ||
end | ||
|
||
def reset_voting_cache | ||
::Category.reset_voting_cache | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseVoting | ||
class TopicVoteCount < ActiveRecord::Base | ||
self.table_name = 'discourse_voting_topic_vote_count' | ||
|
||
belongs_to :topic | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
module DiscourseVoting | ||
class Vote < ActiveRecord::Base | ||
self.table_name = 'discourse_voting_votes' | ||
|
||
belongs_to :user | ||
belongs_to :topic | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.