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/lib/relay.idl b/lib/relay.idl index e0e7bc11e7..34c73c666e 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 diff --git a/public/relay.json b/public/relay.json index 3cc4a0e499..66d1518342 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, 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