mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-18 16:20:12 +01:00
remove unused and unneccesary user_id from taggings table.
this way we can stay closer to the defaults of has_many_polymorphs thus making upgrading easier
This commit is contained in:
parent
65fe971d32
commit
f79c28231b
12 changed files with 1932 additions and 1911 deletions
|
|
@ -7,7 +7,8 @@ class StatsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
@page_title = 'TRACKS::Statistics'
|
@page_title = 'TRACKS::Statistics'
|
||||||
|
|
||||||
@unique_tags = @tags.count(:all, {:group=>"tag_id"})
|
@tags_count = get_total_number_of_tags_of_user
|
||||||
|
@unique_tags_count = get_unique_tags_of_user.count
|
||||||
@hidden_contexts = @contexts.hidden
|
@hidden_contexts = @contexts.hidden
|
||||||
@first_action = @actions.find(:first, :order => "created_at ASC")
|
@first_action = @actions.find(:first, :order => "created_at ASC")
|
||||||
|
|
||||||
|
|
@ -643,11 +644,31 @@ class StatsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def get_unique_tags_of_user
|
||||||
|
tag_ids = @actions.find_by_sql([
|
||||||
|
"SELECT DISTINCT tags.id as id "+
|
||||||
|
"FROM tags, taggings, todos "+
|
||||||
|
"WHERE todos.user_id=? "+
|
||||||
|
"AND tags.id = taggings.tag_id " +
|
||||||
|
"AND taggings.taggable_id = todos.id ", current_user.id])
|
||||||
|
tags_ids_s = tag_ids.map(&:id).sort.join(",")
|
||||||
|
return Tag.find(:all, :conditions => "id in (" + tags_ids_s + ")")
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_total_number_of_tags_of_user
|
||||||
|
# same query as get_unique_tags_of_user except for the DISTINCT
|
||||||
|
return @actions.find_by_sql([
|
||||||
|
"SELECT tags.id as id "+
|
||||||
|
"FROM tags, taggings, todos "+
|
||||||
|
"WHERE todos.user_id=? "+
|
||||||
|
"AND tags.id = taggings.tag_id " +
|
||||||
|
"AND taggings.taggable_id = todos.id ", current_user.id]).count
|
||||||
|
end
|
||||||
|
|
||||||
def init
|
def init
|
||||||
@actions = @user.todos
|
@actions = @user.todos
|
||||||
@projects = @user.projects
|
@projects = @user.projects
|
||||||
@contexts = @user.contexts
|
@contexts = @user.contexts
|
||||||
@tags = @user.tags
|
|
||||||
|
|
||||||
# default chart dimensions
|
# default chart dimensions
|
||||||
@chart_width=460
|
@chart_width=460
|
||||||
|
|
@ -812,9 +833,10 @@ class StatsController < ApplicationController
|
||||||
|
|
||||||
# Get the tag cloud for all tags for actions
|
# Get the tag cloud for all tags for actions
|
||||||
query = "SELECT tags.id, name, count(*) AS count"
|
query = "SELECT tags.id, name, count(*) AS count"
|
||||||
query << " FROM taggings, tags"
|
query << " FROM taggings, tags, todos"
|
||||||
query << " WHERE tags.id = tag_id"
|
query << " WHERE tags.id = tag_id"
|
||||||
query << " AND taggings.user_id="+@user.id.to_s+" "
|
query << " AND taggings.taggable_id = todos.id"
|
||||||
|
query << " AND todos.user_id="+current_user.id.to_s+" "
|
||||||
query << " AND taggings.taggable_type='Todo' "
|
query << " AND taggings.taggable_type='Todo' "
|
||||||
query << " GROUP BY tags.id, tags.name"
|
query << " GROUP BY tags.id, tags.name"
|
||||||
query << " ORDER BY count DESC, name"
|
query << " ORDER BY count DESC, name"
|
||||||
|
|
@ -833,7 +855,7 @@ class StatsController < ApplicationController
|
||||||
query = "SELECT tags.id, tags.name AS name, count(*) AS count"
|
query = "SELECT tags.id, tags.name AS name, count(*) AS count"
|
||||||
query << " FROM taggings, tags, todos"
|
query << " FROM taggings, tags, todos"
|
||||||
query << " WHERE tags.id = tag_id"
|
query << " WHERE tags.id = tag_id"
|
||||||
query << " AND taggings.user_id=? "
|
query << " AND todos.user_id=? "
|
||||||
query << " AND taggings.taggable_type='Todo' "
|
query << " AND taggings.taggable_type='Todo' "
|
||||||
query << " AND taggings.taggable_id=todos.id "
|
query << " AND taggings.taggable_id=todos.id "
|
||||||
query << " AND (todos.created_at > ? OR "
|
query << " AND (todos.created_at > ? OR "
|
||||||
|
|
@ -842,7 +864,7 @@ class StatsController < ApplicationController
|
||||||
query << " ORDER BY count DESC, name"
|
query << " ORDER BY count DESC, name"
|
||||||
query << " LIMIT 100"
|
query << " LIMIT 100"
|
||||||
@tags_for_cloud_90days = Tag.find_by_sql(
|
@tags_for_cloud_90days = Tag.find_by_sql(
|
||||||
[query, @user.id, @cut_off_3months, @cut_off_3months]
|
[query, current_user.id, @cut_off_3months, @cut_off_3months]
|
||||||
).sort_by { |tag| tag.name.downcase }
|
).sort_by { |tag| tag.name.downcase }
|
||||||
|
|
||||||
max_90days, @tags_min_90days = 0, 0
|
max_90days, @tags_min_90days = 0, 0
|
||||||
|
|
|
||||||
|
|
@ -175,10 +175,7 @@ class TodosController < ApplicationController
|
||||||
def update
|
def update
|
||||||
@source_view = params['_source_view'] || 'todo'
|
@source_view = params['_source_view'] || 'todo'
|
||||||
init_data_for_sidebar unless mobile?
|
init_data_for_sidebar unless mobile?
|
||||||
if params[:tag_list]
|
@todo.tag_with(params[:tag_list]) if params[:tag_list]
|
||||||
@todo.tag_with(params[:tag_list])
|
|
||||||
@todo.tags(true) #force a reload for proper rendering
|
|
||||||
end
|
|
||||||
@original_item_context_id = @todo.context_id
|
@original_item_context_id = @todo.context_id
|
||||||
@original_item_project_id = @todo.project_id
|
@original_item_project_id = @todo.project_id
|
||||||
@original_item_was_deferred = @todo.deferred?
|
@original_item_was_deferred = @todo.deferred?
|
||||||
|
|
@ -385,14 +382,14 @@ class TodosController < ApplicationController
|
||||||
tag_collection = @tag.todos
|
tag_collection = @tag.todos
|
||||||
|
|
||||||
@not_done_todos = tag_collection.find(:all,
|
@not_done_todos = tag_collection.find(:all,
|
||||||
:conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'active'],
|
:conditions => ['todos.user_id = ? and state = ?', current_user.id, 'active'],
|
||||||
:order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC')
|
:order => 'todos.due IS NULL, todos.due ASC, todos.created_at ASC')
|
||||||
@hidden_todos = current_user.todos.find(:all,
|
@hidden_todos = current_user.todos.find(:all,
|
||||||
:include => [:taggings, :tags, :context],
|
:include => [:taggings, :tags, :context],
|
||||||
:conditions => ['tags.name = ? AND (todos.state = ? OR (contexts.hide = ? AND todos.state = ?))', @tag_name, 'project_hidden', true, 'active'],
|
:conditions => ['tags.name = ? AND (todos.state = ? OR (contexts.hide = ? AND todos.state = ?))', @tag_name, 'project_hidden', true, 'active'],
|
||||||
:order => 'todos.completed_at DESC, todos.created_at DESC')
|
:order => 'todos.completed_at DESC, todos.created_at DESC')
|
||||||
@deferred = tag_collection.find(:all,
|
@deferred = tag_collection.find(:all,
|
||||||
:conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'deferred'],
|
:conditions => ['todos.user_id = ? and state = ?', current_user.id, 'deferred'],
|
||||||
:order => 'show_from ASC, todos.created_at DESC')
|
:order => 'show_from ASC, todos.created_at DESC')
|
||||||
|
|
||||||
# If you've set no_completed to zero, the completed items box isn't shown on
|
# If you've set no_completed to zero, the completed items box isn't shown on
|
||||||
|
|
@ -400,7 +397,7 @@ class TodosController < ApplicationController
|
||||||
max_completed = current_user.prefs.show_number_completed
|
max_completed = current_user.prefs.show_number_completed
|
||||||
@done = tag_collection.find(:all,
|
@done = tag_collection.find(:all,
|
||||||
:limit => max_completed,
|
:limit => max_completed,
|
||||||
:conditions => ['taggings.user_id = ? and state = ?', current_user.id, 'completed'],
|
:conditions => ['todos.user_id = ? and state = ?', current_user.id, 'completed'],
|
||||||
:order => 'todos.completed_at DESC')
|
:order => 'todos.completed_at DESC')
|
||||||
|
|
||||||
@projects = current_user.projects
|
@projects = current_user.projects
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ class Tagging < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :tag
|
belongs_to :tag
|
||||||
belongs_to :taggable, :polymorphic => true
|
belongs_to :taggable, :polymorphic => true
|
||||||
# belongs_to :user
|
|
||||||
|
|
||||||
# If you also need to use <tt>acts_as_list</tt>, you will have to manage the tagging positions manually by creating decorated join records when you associate Tags with taggables.
|
# If you also need to use <tt>acts_as_list</tt>, you will have to manage the tagging positions manually by creating decorated join records when you associate Tags with taggables.
|
||||||
# acts_as_list :scope => :taggable
|
# acts_as_list :scope => :taggable
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,6 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
has_many :notes, :order => "created_at DESC", :dependent => :delete_all
|
||||||
has_one :preference, :dependent => :destroy
|
has_one :preference, :dependent => :destroy
|
||||||
has_many :taggings
|
|
||||||
has_many :tags, :through => :taggings, :select => "DISTINCT tags.*"
|
|
||||||
|
|
||||||
attr_protected :is_admin
|
attr_protected :is_admin
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ deferred actions. </p>
|
||||||
a total of <%= @actions.count %> actions.
|
a total of <%= @actions.count %> actions.
|
||||||
<%= @actions.count(:conditions => "NOT completed_at IS NULL") %> of these are completed.
|
<%= @actions.count(:conditions => "NOT completed_at IS NULL") %> of these are completed.
|
||||||
|
|
||||||
<p>You have <%= @tags.count-%> tags placed on actions. Of those tags,
|
<p>You have <%= @tags_count-%> tags placed on actions. Of those tags,
|
||||||
<%= @unique_tags.size -%> are unique.
|
<%= @unique_tags_count -%> are unique.
|
||||||
<% end -%>
|
<% end -%>
|
||||||
|
|
||||||
|
|
|
||||||
9
db/migrate/045_remove_user_from_taggings.rb.rb
Normal file
9
db/migrate/045_remove_user_from_taggings.rb.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
class RemoveUserFromTaggings < ActiveRecord::Migration
|
||||||
|
def self.up
|
||||||
|
remove_column :taggings, :user_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
add_column :taggings, :user_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
4
test/fixtures/taggings.yml
vendored
4
test/fixtures/taggings.yml
vendored
|
|
@ -4,14 +4,12 @@ foo_bar1:
|
||||||
tag_id: 1
|
tag_id: 1
|
||||||
taggable_id: 1 # Call Bill Gates
|
taggable_id: 1 # Call Bill Gates
|
||||||
taggable_type: Todo
|
taggable_type: Todo
|
||||||
user_id: 1
|
|
||||||
|
|
||||||
foo_bar2:
|
foo_bar2:
|
||||||
id: 2
|
id: 2
|
||||||
tag_id: 2
|
tag_id: 2
|
||||||
taggable_id: 1 # Call Bill Gates
|
taggable_id: 1 # Call Bill Gates
|
||||||
taggable_type: Todo
|
taggable_type: Todo
|
||||||
user_id: 1
|
|
||||||
|
|
||||||
# Todo 2 should be tagged with foo
|
# Todo 2 should be tagged with foo
|
||||||
foo1:
|
foo1:
|
||||||
|
|
@ -19,11 +17,9 @@ foo1:
|
||||||
tag_id: 1
|
tag_id: 1
|
||||||
taggable_id: 2 # Call dinosaur exterminator
|
taggable_id: 2 # Call dinosaur exterminator
|
||||||
taggable_type: Todo
|
taggable_type: Todo
|
||||||
user_id: 1
|
|
||||||
|
|
||||||
foo2:
|
foo2:
|
||||||
id: 4
|
id: 4
|
||||||
tag_id: 1
|
tag_id: 1
|
||||||
taggable_id: 3 # Buy milk - completed
|
taggable_id: 3 # Buy milk - completed
|
||||||
taggable_type: Todo
|
taggable_type: Todo
|
||||||
user_id: 1
|
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,8 @@ class StatsControllerTest < Test::Unit::TestCase
|
||||||
assert_equal 3, assigns['projects'].count(:conditions => "state = 'active'")
|
assert_equal 3, assigns['projects'].count(:conditions => "state = 'active'")
|
||||||
assert_equal 10, assigns['contexts'].count
|
assert_equal 10, assigns['contexts'].count
|
||||||
assert_equal 16, assigns['actions'].count
|
assert_equal 16, assigns['actions'].count
|
||||||
assert_equal 4, assigns['tags'].count
|
assert_equal 4, assigns['tags_count']
|
||||||
assert_equal 2, assigns['unique_tags'].size
|
assert_equal 2, assigns['unique_tags_count']
|
||||||
assert_equal 2.week.ago.utc.beginning_of_day, assigns['first_action'].created_at
|
assert_equal 2.week.ago.utc.beginning_of_day, assigns['first_action'].created_at
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ class TodosControllerTest < Test::Rails::TestCase
|
||||||
login_as(:admin_user)
|
login_as(:admin_user)
|
||||||
@user = User.find(@request.session['user_id'])
|
@user = User.find(@request.session['user_id'])
|
||||||
tag = Tag.find_by_name('foo').todos
|
tag = Tag.find_by_name('foo').todos
|
||||||
@tagged = tag.find(:all, :conditions => ['taggings.user_id = ?', @user.id]).size
|
@tagged = tag.count
|
||||||
get :tag, :name => 'foo'
|
get :tag, :name => 'foo'
|
||||||
assert_response :success
|
assert_response :success
|
||||||
assert_equal 3, @tagged
|
assert_equal 3, @tagged
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue