From a18426b6c4681644ead60dfe46ec419a83d099f1 Mon Sep 17 00:00:00 2001 From: Nick Lupton <19624419+mr-nick17@users.noreply.github.com> Date: Fri, 6 Jan 2023 11:13:05 +0000 Subject: [PATCH] hotfix to disable parent area count --- .../partials/census/variables-table.tmpl | 2 +- handlers/filter_output.go | 58 ++++---- handlers/filter_output_test.go | 125 +++++++++--------- 3 files changed, 94 insertions(+), 91 deletions(-) diff --git a/assets/templates/partials/census/variables-table.tmpl b/assets/templates/partials/census/variables-table.tmpl index 749faa8..fdfe637 100644 --- a/assets/templates/partials/census/variables-table.tmpl +++ b/assets/templates/partials/census/variables-table.tmpl @@ -31,7 +31,7 @@ {{ if $dim.IsDefaultCoverage }} {{- localise "AreaTypeDefaultCoverage" $language 1 -}} {{ else }} - {{- $dim.Title }} ({{ thousandsSeparator $dim.TotalItems -}}) + {{- $dim.Title }} {{ end }} {{else}} diff --git a/handlers/filter_output.go b/handlers/filter_output.go index 4d53492..83ccd73 100644 --- a/handlers/filter_output.go +++ b/handlers/filter_output.go @@ -29,7 +29,7 @@ func FilterOutput(zc ZebedeeClient, fc FilterClient, pc PopulationClient, dc Dat func filterOutput(w http.ResponseWriter, req *http.Request, zc ZebedeeClient, dc DatasetClient, fc FilterClient, pc PopulationClient, rend RenderClient, cfg config.Config, collectionID, lang, apiRouterVersion, userAccessToken string) { const numOptsSummary = 1000 var initialVersion dataset.Version - var initialVersionReleaseDate, supVar string + var initialVersionReleaseDate string var form = req.URL.Query().Get("f") var format = req.URL.Query().Get("format") var isValidationError bool @@ -221,30 +221,31 @@ func filterOutput(w http.ResponseWriter, req *http.Request, zc ZebedeeClient, dc return nil, 0, fmt.Errorf("failed to get dimension areas") } - if dim.FilterByParent != "" { - count, err := pc.GetParentAreaCount(ctx, population.GetParentAreaCountInput{ - AuthTokens: population.AuthTokens{ - UserAuthToken: userAccessToken, - }, - PopulationType: filterOutput.PopulationType, - AreaTypeID: dim.ID, - ParentAreaTypeID: dim.FilterByParent, - Areas: optsIDs, - SVarID: supVar, - }) - if err != nil { - log.Error(ctx, "failed to get parent area count", err, log.Data{ - "dataset_id": filterOutput.PopulationType, - "area_type_id": dim.ID, - "parent_area_type_id": dim.FilterByParent, - "areas": optsIDs, - "supplementary_variable_id": supVar, - }) - return nil, 0, err - } - - totalCount = count - } + // TODO: pc.GetParentAreaCount is causing production issues + // if dim.FilterByParent != "" { + // count, err := pc.GetParentAreaCount(ctx, population.GetParentAreaCountInput{ + // AuthTokens: population.AuthTokens{ + // UserAuthToken: userAccessToken, + // }, + // PopulationType: filterOutput.PopulationType, + // AreaTypeID: dim.ID, + // ParentAreaTypeID: dim.FilterByParent, + // Areas: optsIDs, + // SVarID: supVar, + // }) + // if err != nil { + // log.Error(ctx, "failed to get parent area count", err, log.Data{ + // "dataset_id": filterOutput.PopulationType, + // "area_type_id": dim.ID, + // "parent_area_type_id": dim.FilterByParent, + // "areas": optsIDs, + // "supplementary_variable_id": supVar, + // }) + // return nil, 0, err + // } + + // totalCount = count + // } return options, totalCount, nil } @@ -259,9 +260,10 @@ func filterOutput(w http.ResponseWriter, req *http.Request, zc ZebedeeClient, dc var fDims []model.FilterDimension for i := len(filterOutput.Dimensions) - 1; i >= 0; i-- { - if filterOutput.Dimensions[i].IsAreaType == nil || !*filterOutput.Dimensions[i].IsAreaType { - supVar = filterOutput.Dimensions[i].ID - } + // TODO: pc.GetParentAreaCount is causing production issues + // if filterOutput.Dimensions[i].IsAreaType == nil || !*filterOutput.Dimensions[i].IsAreaType { + // supVar = filterOutput.Dimensions[i].ID + // } options, count, err := getOptions(filterOutput.Dimensions[i]) if err != nil { log.Error(ctx, "failed to get options for dimension", err, log.Data{"dimension_name": filterOutput.Dimensions[i].Name}) diff --git a/handlers/filter_output_test.go b/handlers/filter_output_test.go index 51c743f..39c3b40 100644 --- a/handlers/filter_output_test.go +++ b/handlers/filter_output_test.go @@ -635,10 +635,11 @@ func TestFilterOutputHandler(t *testing.T) { EXPECT(). GetArea(gomock.Any(), gomock.Any()). Return(population.GetAreaResponse{}, nil) - mockPc. - EXPECT(). - GetParentAreaCount(gomock.Any(), gomock.Any()). - Return(0, nil) + // TODO: pc.GetParentAreaCount is causing production issues + // mockPc. + // EXPECT(). + // GetParentAreaCount(gomock.Any(), gomock.Any()). + // Return(0, nil) mockRend := NewMockRenderClient(mockCtrl) mockRend. @@ -893,69 +894,69 @@ func TestFilterOutputHandler(t *testing.T) { // GetVersion(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", "1"). // Return(versions.Items[0], nil) - Convey("and the additional call to pc.GetParentAreaCount fails", func() { - mockDc := NewMockDatasetClient(mockCtrl) - mockDc. - EXPECT(). - Get(ctx, userAuthToken, serviceAuthToken, collectionID, "12345"). - Return(dataset.DatasetDetails{ - Contacts: &[]dataset.Contact{{Name: "Nick"}}, - Type: "flexible", - URI: "/economy/grossdomesticproduct/datasets/gdpjanuary2018", - Links: dataset.Links{ - LatestVersion: dataset.Link{ - URL: "/datasets/12345/editions/2021/versions/1", - }, - }, - ID: "12345", - }, nil) - mockDc. - EXPECT(). - GetVersions(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", &dataset.QueryParams{Offset: 0, Limit: 1000}). - Return(versions, nil) - mockDc. - EXPECT(). - GetVersion(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", "1"). - Return(versions.Items[0], nil) + // Convey("and the additional call to pc.GetParentAreaCount fails", func() { + // mockDc := NewMockDatasetClient(mockCtrl) + // mockDc. + // EXPECT(). + // Get(ctx, userAuthToken, serviceAuthToken, collectionID, "12345"). + // Return(dataset.DatasetDetails{ + // Contacts: &[]dataset.Contact{{Name: "Nick"}}, + // Type: "flexible", + // URI: "/economy/grossdomesticproduct/datasets/gdpjanuary2018", + // Links: dataset.Links{ + // LatestVersion: dataset.Link{ + // URL: "/datasets/12345/editions/2021/versions/1", + // }, + // }, + // ID: "12345", + // }, nil) + // mockDc. + // EXPECT(). + // GetVersions(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", &dataset.QueryParams{Offset: 0, Limit: 1000}). + // Return(versions, nil) + // mockDc. + // EXPECT(). + // GetVersion(ctx, userAuthToken, serviceAuthToken, collectionID, "", "12345", "2021", "1"). + // Return(versions.Items[0], nil) - mockFc := NewMockFilterClient(mockCtrl) - mockFc. - EXPECT(). - GetOutput(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(filterModels[3], nil) - mockFc. - EXPECT(). - GetDimensionOptions(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). - Return(filter.DimensionOptions{ - Items: []filter.DimensionOption{ - { - Option: "area 1", - }, - }, - TotalCount: 1, - }, "", nil) + // mockFc := NewMockFilterClient(mockCtrl) + // mockFc. + // EXPECT(). + // GetOutput(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + // Return(filterModels[3], nil) + // mockFc. + // EXPECT(). + // GetDimensionOptions(ctx, gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()). + // Return(filter.DimensionOptions{ + // Items: []filter.DimensionOption{ + // { + // Option: "area 1", + // }, + // }, + // TotalCount: 1, + // }, "", nil) - mockPc := NewMockPopulationClient(mockCtrl) - mockPc. - EXPECT(). - GetArea(gomock.Any(), gomock.Any()). - Return(population.GetAreaResponse{}, nil) - mockPc. - EXPECT(). - GetParentAreaCount(gomock.Any(), gomock.Any()). - Return(0, errors.New("area parent count client error")) + // mockPc := NewMockPopulationClient(mockCtrl) + // mockPc. + // EXPECT(). + // GetArea(gomock.Any(), gomock.Any()). + // Return(population.GetAreaResponse{}, nil) + // mockPc. + // EXPECT(). + // GetParentAreaCount(gomock.Any(), gomock.Any()). + // Return(0, errors.New("area parent count client error")) - w := httptest.NewRecorder() - req := httptest.NewRequest("GET", "/datasets/12345/editions/2021/versions/1/filter-outputs/67890", nil) + // w := httptest.NewRecorder() + // req := httptest.NewRequest("GET", "/datasets/12345/editions/2021/versions/1/filter-outputs/67890", nil) - router := mux.NewRouter() - router.HandleFunc("/datasets/{datasetID}/editions/{editionID}/versions/{versionID}/filter-outputs/{filterOutputID}", FilterOutput(mockZebedeeClient, mockFc, mockPc, mockDc, NewMockRenderClient(mockCtrl), cfg, "")) + // router := mux.NewRouter() + // router.HandleFunc("/datasets/{datasetID}/editions/{editionID}/versions/{versionID}/filter-outputs/{filterOutputID}", FilterOutput(mockZebedeeClient, mockFc, mockPc, mockDc, NewMockRenderClient(mockCtrl), cfg, "")) - router.ServeHTTP(w, req) - Convey("Then the status code is 500", func() { - So(w.Code, ShouldEqual, http.StatusInternalServerError) - }) - }) + // router.ServeHTTP(w, req) + // Convey("Then the status code is 500", func() { + // So(w.Code, ShouldEqual, http.StatusInternalServerError) + // }) + // }) }) }) }