diff --git a/app/graph/types/project_group_type.rb b/app/graph/types/project_group_type.rb index aad98569c2..bdcd6e0a34 100644 --- a/app/graph/types/project_group_type.rb +++ b/app/graph/types/project_group_type.rb @@ -8,7 +8,6 @@ class ProjectGroupType < DefaultObject field :description, GraphQL::Types::String, null: true field :team_id, GraphQL::Types::Int, null: true field :team, PublicTeamType, null: true - field :medias_count, GraphQL::Types::Int, null: true field :projects, ProjectType.connection_type, null: true end diff --git a/app/graph/types/project_type.rb b/app/graph/types/project_type.rb index ab39118c35..ed215af54d 100644 --- a/app/graph/types/project_type.rb +++ b/app/graph/types/project_type.rb @@ -9,7 +9,6 @@ class ProjectType < DefaultObject field :dbid, GraphQL::Types::Int, null: true field :permissions, GraphQL::Types::String, null: true field :pusher_channel, GraphQL::Types::String, null: true - field :medias_count, GraphQL::Types::Int, null: true field :search_id, GraphQL::Types::String, null: true field :url, GraphQL::Types::String, null: true field :search, CheckSearchType, null: true diff --git a/app/models/project.rb b/app/models/project.rb index 4d579bccfb..26c669a91e 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -40,41 +40,6 @@ class Project < ApplicationRecord check_settings - cached_field :medias_count, - start_as: 0, - recalculate: :recalculate_medias_count, - update_on: [ - { - model: Relationship, - affected_ids: proc { |r| ProjectMedia.where(id: r.target_id).map(&:project_id) }, - events: { - save: :recalculate, - destroy: :recalculate - } - }, - { - model: ProjectMedia, - if: proc { |pm| !pm.project_id.nil? }, - affected_ids: proc { |pm| [pm.project_id] }, - events: { - create: :recalculate, - destroy: :recalculate - } - }, - { - model: ProjectMedia, - if: proc { |pm| pm.saved_change_to_archived? || pm.saved_change_to_project_id? }, - affected_ids: proc { |pm| [pm.project_id, pm.project_id_before_last_save] }, - events: { - update: :recalculate, - } - }, - ] - - def recalculate_medias_count - self.team.medias_count(self) - end - def check_search_team self.team.check_search_team end diff --git a/app/models/project_group.rb b/app/models/project_group.rb index 6b5c767b04..78303a9f6e 100644 --- a/app/models/project_group.rb +++ b/app/models/project_group.rb @@ -7,10 +7,6 @@ class ProjectGroup < ApplicationRecord belongs_to :team, optional: true has_many :projects, dependent: :nullify - def medias_count - self.projects.map(&:medias_count).sum - end - def project_medias ProjectMedia.joins(:project).where('projects.project_group_id' => self.id) end diff --git a/lib/relay.idl b/lib/relay.idl index e0e7bc11e7..5edaad82c4 100644 --- a/lib/relay.idl +++ b/lib/relay.idl @@ -10495,7 +10495,6 @@ type Project implements Node { description: String id: ID! is_default: Boolean - medias_count: Int permissions: String privacy: Int project_group: ProjectGroup @@ -10574,7 +10573,6 @@ type ProjectGroup implements Node { dbid: Int description: String id: ID! - medias_count: Int permissions: String projects( """ diff --git a/public/relay.json b/public/relay.json index 3cc4a0e499..8f9e81dfe1 100644 --- a/public/relay.json +++ b/public/relay.json @@ -56720,20 +56720,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "medias_count", - "description": null, - "args": [ - - ], - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "permissions", "description": null, @@ -57156,20 +57142,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "medias_count", - "description": null, - "args": [ - - ], - "type": { - "kind": "SCALAR", - "name": "Int", - "ofType": null - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "permissions", "description": null, diff --git a/test/controllers/graphql_controller_4_test.rb b/test/controllers/graphql_controller_4_test.rb index 2bdd4ef54b..60dc8f83b1 100644 --- a/test/controllers/graphql_controller_4_test.rb +++ b/test/controllers/graphql_controller_4_test.rb @@ -47,7 +47,6 @@ def teardown test "should bulk-send project medias to trash" do @pms.each { |pm| assert_equal CheckArchivedFlags::FlagCodes::NONE, pm.archived } - @ps.each { |p| assert_equal 1, p.reload.medias_count } assert_search_finds_all({ archived: CheckArchivedFlags::FlagCodes::NONE }) assert_search_finds_none({ archived: CheckArchivedFlags::FlagCodes::TRASHED }) assert_equal 0, CheckPusher::Worker.jobs.size @@ -57,7 +56,6 @@ def teardown assert_response :success @pms.each { |pm| assert_equal CheckArchivedFlags::FlagCodes::TRASHED, pm.reload.archived } - @ps.each { |p| assert_equal 0, p.reload.medias_count } assert_search_finds_all({ archived: CheckArchivedFlags::FlagCodes::TRASHED }) assert_search_finds_none({ archived: CheckArchivedFlags::FlagCodes::NONE }) assert_equal 1, CheckPusher::Worker.jobs.size @@ -90,7 +88,6 @@ def teardown Sidekiq::Worker.drain_all sleep 1 @pms.each { |pm| assert_equal CheckArchivedFlags::FlagCodes::TRASHED, pm.reload.archived } - @ps.each { |p| assert_equal 0, p.reload.medias_count } assert_search_finds_all({ archived: CheckArchivedFlags::FlagCodes::TRASHED }) assert_search_finds_none({ archived: CheckArchivedFlags::FlagCodes::NONE }) assert_equal 0, CheckPusher::Worker.jobs.size @@ -100,7 +97,6 @@ def teardown assert_response :success @pms.each { |pm| assert_equal CheckArchivedFlags::FlagCodes::NONE, pm.reload.archived } - @ps.each { |p| assert_equal 1, p.reload.medias_count } assert_search_finds_all({ archived: CheckArchivedFlags::FlagCodes::NONE }) assert_search_finds_none({ archived: CheckArchivedFlags::FlagCodes::TRASHED }) assert_equal 1, CheckPusher::Worker.jobs.size @@ -113,7 +109,6 @@ def teardown Sidekiq::Worker.drain_all sleep 1 @pms.each { |pm| assert_equal CheckArchivedFlags::FlagCodes::TRASHED, pm.reload.archived } - @ps.each { |p| assert_equal 0, p.reload.medias_count } assert_search_finds_all({ archived: CheckArchivedFlags::FlagCodes::TRASHED }) assert_search_finds_none({ archived: CheckArchivedFlags::FlagCodes::NONE }) assert_equal 0, CheckPusher::Worker.jobs.size @@ -123,8 +118,6 @@ def teardown assert_response :success @pms.each { |pm| assert_equal CheckArchivedFlags::FlagCodes::NONE, pm.reload.archived } - @ps.each { |p| assert_equal 0, p.reload.medias_count } - assert_equal @pms.length, add_to.reload.medias_count assert_search_finds_all({ archived: CheckArchivedFlags::FlagCodes::NONE }) assert_search_finds_none({ archived: CheckArchivedFlags::FlagCodes::TRASHED }) assert_equal 2, CheckPusher::Worker.jobs.size @@ -291,17 +284,11 @@ def teardown invalid_id_1 = Base64.encode64("ProjectMedia/0") invalid_id_2 = Base64.encode64("Project/#{pm1.id}") invalid_id_3 = random_string - assert_equal 4, @p1.reload.medias_count - assert_equal 2, @p2.reload.medias_count - assert_equal 0, p4.reload.medias_count ids = [] [@pm1.graphql_id, @pm2.graphql_id, pm1.graphql_id, pm2.graphql_id, invalid_id_1, invalid_id_2, invalid_id_3].each { |id| ids << id } query = 'mutation { updateProjectMedias(input: { clientMutationId: "1", ids: ' + ids.to_json + ', action: "move_to", params: "{\"move_to\": \"' + p4.id.to_s + '\"}" }) { team { dbid } } }' post :create, params: { query: query, team: @t.slug } assert_response :success - assert_equal 0, @p1.reload.medias_count - assert_equal 0, @p2.reload.medias_count - assert_equal 6, p4.reload.medias_count # verify move similar items assert_equal p4.id, t_pm1.reload.project_id assert_equal p4.id, t2_pm1.reload.project_id diff --git a/test/controllers/graphql_controller_test.rb b/test/controllers/graphql_controller_test.rb index 839ddaf9bd..786141273f 100644 --- a/test/controllers/graphql_controller_test.rb +++ b/test/controllers/graphql_controller_test.rb @@ -397,7 +397,7 @@ def setup p = create_project team: t pm = create_project_media project: p create_comment annotated: pm, annotator: u - query = "query GetById { project(id: \"#{p.id}\") { medias_count, project_medias(first: 1) { edges { node { permissions } } } } }" + query = "query GetById { project(id: \"#{p.id}\") { project_medias(first: 1) { edges { node { permissions } } } } }" post :create, params: { query: query, team: 'team' } assert_response :success assert_not_equal '{}', JSON.parse(@response.body)['data']['project']['project_medias']['edges'][0]['node']['permissions'] diff --git a/test/models/project_group_test.rb b/test/models/project_group_test.rb index 959000629f..a8bcf2b6ec 100644 --- a/test/models/project_group_test.rb +++ b/test/models/project_group_test.rb @@ -36,28 +36,6 @@ def setup assert_equal [pg], t.reload.project_groups end - test "should have medias count" do - RequestStore.store[:skip_cached_field_update] = false - t = create_team - pg = create_project_group team: t - assert_equal 0, pg.medias_count - p1 = create_project team: t - p1.project_group = pg - p1.save! - assert_equal 0, p1.medias_count - create_project_media project: p1 - assert_equal 1, p1.medias_count - create_project_media project: p1 - assert_equal 2, p1.medias_count - p2 = create_project team: t - p2.project_group = pg - p2.save! - assert_equal 0, p2.medias_count - create_project_media project: p2 - assert_equal 1, p2.medias_count - assert_equal 3, pg.reload.medias_count - end - test "should have project medias" do t = create_team pg = create_project_group team: t diff --git a/test/models/project_test.rb b/test/models/project_test.rb index 39362aa68d..e278d7ef50 100644 --- a/test/models/project_test.rb +++ b/test/models/project_test.rb @@ -121,14 +121,6 @@ def setup assert_equal [m1, m2].sort, p.reload.project_medias.map(&:media).sort end - test "should get project medias count" do - t = create_team - p = create_project team: t - create_project_media project: p - create_project_media project: p - assert_equal 2, p.medias_count - end - test "should have annotations" do pm = create_project_media c1 = create_comment annotated: nil @@ -550,42 +542,11 @@ def setup end end - test "should not include trashed items in medias count" do - p = create_project - create_project_media project: p - create_project_media project: p - create_project_media project: p, archived: CheckArchivedFlags::FlagCodes::TRASHED - assert_equal 2, p.reload.medias_count - end - test "should have search team" do assert_kind_of CheckSearch, create_project.check_search_team assert_kind_of Array, create_project.check_search_team.projects end - test "should cache medias_count" do - RequestStore.store[:skip_cached_field_update] = false - t = create_team - p = create_project team: t - pm1 = create_project_media team: t, project: nil - pm2 = create_project_media team: t, project: nil - pm3 = create_project_media team: t, project: nil - assert_equal 0, p.reload.medias_count - pm1.project_id = p.id; pm1.save! - assert_equal 1, p.reload.medias_count - pm2.project_id = p.id; pm2.save! - assert_equal 2, p.reload.medias_count - pm3.project_id = p.id; pm3.save! - assert_equal 3, p.reload.medias_count - pm3.destroy! - assert_equal 2, p.reload.medias_count - assert_equal 0, pm2.reload.sources_count - r = create_relationship source_id: pm1.id, target_id: pm2.id, relationship_type: Relationship.confirmed_type - assert_equal 1, pm2.reload.sources_count - assert_equal 1, p.reload.medias_count - RequestStore.store[:skip_cached_field_update] = true - end - test "should have a project group" do t = create_team p = create_project team: t @@ -657,8 +618,6 @@ def setup p2.items_destination_project_id = p3.id p2.destroy assert_equal [pm3.id, pm4.id], p3.reload.project_media_ids.sort - # assert_equal p3.title, pm3.folder - assert_equal 2, p3.medias_count end end RequestStore.store[:skip_cached_field_update] = true diff --git a/test/models/relationship_test.rb b/test/models/relationship_test.rb index 8eca19286e..455ba30880 100644 --- a/test/models/relationship_test.rb +++ b/test/models/relationship_test.rb @@ -17,13 +17,9 @@ def setup pm2 = create_project_media team: t, project: p2 assert_equal p1, pm1.reload.project assert_equal p2, pm2.reload.project - assert_equal 1, p1.reload.medias_count - assert_equal 1, p2.reload.medias_count r = create_relationship relationship_type: Relationship.confirmed_type, source_id: pm1.id, target_id: pm2.id assert_equal p1, pm1.reload.project assert_equal p1, pm2.reload.project - assert_equal 1, p1.reload.medias_count - assert_equal 0, p2.reload.medias_count end test "should create relationship between items with same media" do diff --git a/test/models/team_2_test.rb b/test/models/team_2_test.rb index 1542c9491e..3906def153 100644 --- a/test/models/team_2_test.rb +++ b/test/models/team_2_test.rb @@ -1117,16 +1117,12 @@ def setup t.rules = rules.to_json t.save! pm1 = create_project_media project: p0, disable_es_callbacks: false - assert_equal 1, p0.reload.medias_count - assert_equal 0, p1.reload.medias_count s = pm1.last_status_obj s.status = 'in_progress' s.save! sleep 2 result = $repository.find(get_es_id(pm1)) assert_equal p1.id, result['project_id'] - assert_equal 0, p0.reload.medias_count - assert_equal 1, p1.reload.medias_count pm2 = create_project_media project: p0, disable_es_callbacks: false sleep 2 assert_equal p1.id, pm1.reload.project_id diff --git a/test/models/team_test.rb b/test/models/team_test.rb index fabbc09b52..2b0f0c176d 100644 --- a/test/models/team_test.rb +++ b/test/models/team_test.rb @@ -515,7 +515,6 @@ def setup u = create_user create_team_user team: t, user: u assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count rules = [] rules << { "name": random_string, @@ -547,7 +546,6 @@ def setup create_project_media team: t create_project_media user: u assert_equal 1, p.reload.project_medias.count - assert_equal 1, p.reload.medias_count end test "should set default language when creating team" do @@ -573,7 +571,6 @@ def setup u2 = create_user create_team_user team: t, user: u assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count rules = [] rules << { "name": random_string, @@ -636,7 +633,6 @@ def setup assert_equal 0, pm2.reload.archived assert_equal 0, pm3.reload.archived assert_equal 1, p.reload.project_medias.count - assert_equal 1, p.reload.medias_count end test "should create default fieldsets when team is created" do @@ -670,7 +666,6 @@ def setup p = create_project team: t pm = create_project_media team: t assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count rules = [] rules << { "name": random_string, @@ -702,12 +697,10 @@ def setup tk.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: { selected: 'Bar' }.to_json }.to_json }.to_json tk.save! assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count tk = Task.find(tk.id) tk.response = { annotation_type: 'task_response_single_choice', set_fields: { response_single_choice: { selected: 'Foo' }.to_json }.to_json }.to_json tk.save! assert_equal 1, p.reload.project_medias.count - assert_equal 1, p.reload.medias_count end test "should match rule by assignment" do @@ -719,7 +712,6 @@ def setup p = create_project team: t pm = create_project_media team: t assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count rules = [] rules << { "name": random_string, @@ -749,7 +741,6 @@ def setup t.save! Assignment.create! assigned: pm.last_status_obj.becomes(Annotation), assigner: create_user, user: u assert_equal 1, p.reload.project_medias.count - assert_equal 1, p.reload.medias_count end test "should match rule by text task answer" do @@ -760,7 +751,6 @@ def setup p = create_project team: t pm = create_project_media team: t assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count rules = [] rules << { "name": random_string, @@ -792,12 +782,10 @@ def setup tk.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'test test' }.to_json }.to_json tk.save! assert_equal 0, p.reload.project_medias.count - assert_equal 0, p.reload.medias_count tk = Task.find(tk.id) tk.response = { annotation_type: 'task_response_free_text', set_fields: { response_free_text: 'test foo test' }.to_json }.to_json tk.save! assert_equal 1, p.reload.project_medias.count - assert_equal 1, p.reload.medias_count end test "should allow default BotUser to be added on creation" do