Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

쿼리 최적화 및 백엔드 코드 리팩토링 #152

Open
26 of 27 tasks
906bc906 opened this issue Nov 29, 2022 · 3 comments
Open
26 of 27 tasks

쿼리 최적화 및 백엔드 코드 리팩토링 #152

906bc906 opened this issue Nov 29, 2022 · 3 comments
Assignees
Labels
backend 백엔드 작업 내용 enhancement 최적화 및 개선 작업
Milestone

Comments

@906bc906
Copy link
Collaborator

906bc906 commented Nov 29, 2022

이 이슈가 다루는 문제

  • 모든 쿼리 최적화 및 API Response 포맷 가능한 통일
    • user
      • put :userid
      • get :userid
      • post :userid/avatar
      • put :id/notification-setting 미지원
      • delete :id soft delete로 구현 예정 by @namhyo01
      • get mentionlist 1.4s -> 340ms
      • get search
    • follow
      • get list/follower/:targetid?
      • get list/following/:targetid
      • post following/:targetid
      • delete following/:targetid
      • get check/:targetid
    • post
      • get newsfeed 3s -> 2ms
      • get author/:userid
      • post
      • get :id
      • patch :id
      • delete :id
      • get comments/:id?limit&next 1100ms -> 2ms
      • get search?keyword&next
    • img
      • post image
    • notification
      • get list?next
      • delete list
      • get count
      • delete id/:notif_id
  • 중구난방 const 상수, DTO 미사용 등 개선하여 코드 포맷 통일

이 이슈를 해결한 방법

학습 내용

@906bc906 906bc906 added enhancement 최적화 및 개선 작업 backend 백엔드 작업 내용 labels Nov 29, 2022
@906bc906 906bc906 added this to the Week 4 milestone Nov 29, 2022
@906bc906 906bc906 self-assigned this Nov 29, 2022
@906bc906 906bc906 added this to Moheyum Nov 29, 2022
@906bc906 906bc906 moved this to Todo in Moheyum Nov 29, 2022
@906bc906 906bc906 moved this from Todo to In Progress in Moheyum Nov 30, 2022
@906bc906
Copy link
Collaborator Author

@906bc906
Copy link
Collaborator Author

post get comment

{ explainVersion: '1',
  stages: 
   [ { '$cursor': 
        { queryPlanner: 
           { namespace: 'moheyum.posts',
             indexFilterSet: false,
             parsedQuery: 
              { '$and': 
                 [ { '$expr': { '$eq': [ '$parentPost', { '$const': '63855ba030435bbbe85d2682' } ] } },
                   { parentPost: { '$_internalExprEq': '63855ba030435bbbe85d2682' } } ] },
             queryHash: 'F805C04B',
             planCacheKey: 'F805C04B',
             maxIndexedOrSolutionsReached: false,
             maxIndexedAndSolutionsReached: false,
             maxScansToExplodeReached: false,
             winningPlan: 
              { stage: 'LIMIT',
                limitAmount: 10,
                inputStage: 
                 { stage: 'PROJECTION_DEFAULT',
                   transformBy: 
                    { _id: 1,
                      author: 1,
                      authorDetail: 1,
                      childPosts: 1,
                      createdAt: 1,
                      description: 1,
                      parentPost: 1,
                      title: 1,
                      updateAt: 1,
                      'user.bio': 1,
                      'user.email': 1,
                      'user.follower': 1,
                      'user.following': 1,
                      'user.nickname': 1,
                      'user.postcount': 1,
                      'user.profileimg': 1,
                      'user.state': 1 },
                   inputStage: 
                    { stage: 'FETCH',
                      filter: 
                       { '$and': 
                          [ { '$expr': { '$eq': [ '$parentPost', { '$const': '63855ba030435bbbe85d2682' } ] } },
                            { parentPost: { '$_internalExprEq': '63855ba030435bbbe85d2682' } } ] },
                      inputStage: 
                       { stage: 'IXSCAN',
                         keyPattern: { _id: 1 },
                         indexName: '_id_',
                         isMultiKey: false,
                         multiKeyPaths: { _id: [] },
                         isUnique: true,
                         isSparse: false,
                         isPartial: false,
                         indexVersion: 2,
                         direction: 'forward',
                         indexBounds: { _id: [ '[MinKey, MaxKey]' ] } } } } },
             rejectedPlans: 
              [ { stage: 'LIMIT',
                  limitAmount: 10,
                  inputStage: 
                   { stage: 'PROJECTION_DEFAULT',
                     transformBy: 
                      { _id: 1,
                        author: 1,
                        authorDetail: 1,
                        childPosts: 1,
                        createdAt: 1,
                        description: 1,
                        parentPost: 1,
                        title: 1,
                        updateAt: 1,
                        'user.bio': 1,
                        'user.email': 1,
                        'user.follower': 1,
                        'user.following': 1,
                        'user.nickname': 1,
                        'user.postcount': 1,
                        'user.profileimg': 1,
                        'user.state': 1 },
                     inputStage: 
                      { stage: 'FETCH',
                        filter: 
                         { '$and': 
                            [ { '$expr': { '$eq': [ '$parentPost', { '$const': '63855ba030435bbbe85d2682' } ] } },
                              { parentPost: { '$_internalExprEq': '63855ba030435bbbe85d2682' } } ] },
                        inputStage: 
                         { stage: 'IXSCAN',
                           keyPattern: { _id: 1, author: 1 },
                           indexName: '_id_1_author_1',
                           isMultiKey: false,
                           multiKeyPaths: { _id: [], author: [] },
                           isUnique: false,
                           isSparse: false,
                           isPartial: false,
                           indexVersion: 2,
                           direction: 'forward',
                           indexBounds: { _id: [ '[MinKey, MaxKey]' ], author: [ '[MinKey, MaxKey]' ] } } } } } ] },
          executionStats: 
           { executionSuccess: true,
             nReturned: 2,
             executionTimeMillis: 1101,
             totalKeysExamined: 500630,
             totalDocsExamined: 500630,
             executionStages: 
              { stage: 'LIMIT',
                nReturned: 2,
                executionTimeMillisEstimate: 134,
                works: 500631,
                advanced: 2,
                needTime: 500628,
                needYield: 0,
                saveState: 651,
                restoreState: 651,
                isEOF: 1,
                limitAmount: 10,
                inputStage: 
                 { stage: 'PROJECTION_DEFAULT',
                   nReturned: 2,
                   executionTimeMillisEstimate: 130,
                   works: 500631,
                   advanced: 2,
                   needTime: 500628,
                   needYield: 0,
                   saveState: 651,
                   restoreState: 651,
                   isEOF: 1,
                   transformBy: 
                    { _id: 1,
                      author: 1,
                      authorDetail: 1,
                      childPosts: 1,
                      createdAt: 1,
                      description: 1,
                      parentPost: 1,
                      title: 1,
                      updateAt: 1,
                      'user.bio': 1,
                      'user.email': 1,
                      'user.follower': 1,
                      'user.following': 1,
                      'user.nickname': 1,
                      'user.postcount': 1,
                      'user.profileimg': 1,
                      'user.state': 1 },
                   inputStage: 
                    { stage: 'FETCH',
                      filter: 
                       { '$and': 
                          [ { '$expr': { '$eq': [ '$parentPost', { '$const': '63855ba030435bbbe85d2682' } ] } },
                            { parentPost: { '$_internalExprEq': '63855ba030435bbbe85d2682' } } ] },
                      nReturned: 2,
                      executionTimeMillisEstimate: 124,
                      works: 500631,
                      advanced: 2,
                      needTime: 500628,
                      needYield: 0,
                      saveState: 651,
                      restoreState: 651,
                      isEOF: 1,
                      docsExamined: 500630,
                      alreadyHasObj: 0,
                      inputStage: 
                       { stage: 'IXSCAN',
                         nReturned: 500630,
                         executionTimeMillisEstimate: 49,
                         works: 500631,
                         advanced: 500630,
                         needTime: 0,
                         needYield: 0,
                         saveState: 651,
                         restoreState: 651,
                         isEOF: 1,
                         keyPattern: { _id: 1 },
                         indexName: '_id_',
                         isMultiKey: false,
                         multiKeyPaths: { _id: [] },
                         isUnique: true,
                         isSparse: false,
                         isPartial: false,
                         indexVersion: 2,
                         direction: 'forward',
                         indexBounds: { _id: [ '[MinKey, MaxKey]' ] },
                         keysExamined: 500630,
                         seeks: 1,
                         dupsTested: 0,
                         dupsDropped: 0 } } } } } },
       nReturned: 2,
       executionTimeMillisEstimate: 612 },
     { '$lookup': 
        { from: 'users',
          as: 'user',
          localField: 'author',
          foreignField: 'userid',
          unwinding: { preserveNullAndEmptyArrays: false } },
       totalDocsExamined: 1,
       totalKeysExamined: 1,
       collectionScans: 0,
       indexesUsed: [ 'userid_1' ],
       nReturned: 2,
       executionTimeMillisEstimate: 614 },
     { '$project': 
        { _id: true,
          author: '$author',
          title: '$title',
          description: '$description',
          createdAt: '$createdAt',
          updatedAt: '$updateAt',
          parentPost: '$parentPost',
          childPosts: { '$size': [ '$childPosts' ] },
          authorDetail: 
           { nickname: '$user.nickname',
             email: '$user.email',
             profileimg: '$user.profileimg',
             bio: '$user.bio',
             userState: '$user.state',
             following: '$user.following',
             postcount: '$user.postcount',
             follower: '$user.follower' } },
       nReturned: 2,
       executionTimeMillisEstimate: 614 } ],
  serverInfo: 
   { host: 'db-only',
     port: 27017,
     version: '6.0.2',
     gitVersion: '94fb7dfc8b974f1f5343e7ea394d0d9deedba50e' },
  serverParameters: 
   { internalQueryFacetBufferSizeBytes: 104857600,
     internalQueryFacetMaxOutputDocSizeBytes: 104857600,
     internalLookupStageIntermediateDocumentMaxSizeBytes: 104857600,
     internalDocumentSourceGroupMaxMemoryBytes: 104857600,
     internalQueryMaxBlockingSortMemoryUsageBytes: 104857600,
     internalQueryProhibitBlockingMergeOnMongoS: 0,
     internalQueryMaxAddToSetBytes: 104857600,
     internalDocumentSourceSetWindowFieldsMaxMemoryBytes: 104857600 },
  command: 
   { aggregate: 'posts',
     pipeline: 
      [ { '$sort': { _id: 1 } },
        { '$match': { '$expr': { '$eq': [ '$parentPost', '63855ba030435bbbe85d2682' ] } } },
        { '$limit': 10 },
        { '$lookup': 
           { from: 'users',
             localField: 'author',
             foreignField: 'userid',
             as: 'user' } },
        { '$unwind': '$user' },
        { '$project': 
           { author: '$author',
             title: '$title',
             description: '$description',
             createdAt: '$createdAt',
             updatedAt: '$updateAt',
             parentPost: '$parentPost',
             childPosts: { '$size': '$childPosts' },
             authorDetail: 
              { nickname: '$user.nickname',
                email: '$user.email',
                profileimg: '$user.profileimg',
                bio: '$user.bio',
                userState: '$user.state',
                following: '$user.following',
                postcount: '$user.postcount',
                follower: '$user.follower' } } } ],
     cursor: {},
     '$db': 'moheyum' },
  ok: 1 }

@906bc906 906bc906 moved this from In Progress to Stuck in Moheyum Nov 30, 2022
@906bc906
Copy link
Collaborator Author

DTO 및 코드 포맷 통일은 6주차로 미룹니다.

@906bc906 906bc906 moved this from Stuck to In Progress in Moheyum Dec 13, 2022
namhyo01 added a commit that referenced this issue Dec 15, 2022
namhyo01 added a commit that referenced this issue Dec 15, 2022
namhyo01 added a commit that referenced this issue Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend 백엔드 작업 내용 enhancement 최적화 및 개선 작업
Projects
Status: In Progress
Development

No branches or pull requests

1 participant