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

Run area aggregate (stats) updates only for an area and its ancestors #319

Closed
vnugent opened this issue Jun 17, 2023 · 5 comments
Closed
Assignees

Comments

@vnugent
Copy link
Contributor

vnugent commented Jun 17, 2023

Frontend issue: OpenBeta/open-tacos#877

Background

  • Currently, the only way to update area statistics is by manually running a Kubernetes job.
  • The job only updates USA tree
  • Slow ~ 25 minutes
# The Kubernetes job calls
yarn update-stats

which calls https://github.com/OpenBeta/openbeta-graphql/blob/develop/src/db/utils/jobs/UpdateStatsJob.ts

To do

Based on recent work for issue #213 we can introduce a similar function to only update the affected subtree

@siman4457
Copy link
Contributor

I'll take a crack at this.

@siman4457
Copy link
Contributor

Updating a climb's stats affects its parents.

Potential Solution:

I don't think we have a way of referencing parent nodes. This can be fixed by adding a reference to parent nodes:

{
  "_id": {
    "$oid": "6467ab2ae622317bdb3ef74c"
  },
  "area_name": "Indian Creek",
  "climbs": [],
  "children": [
    ...    
  ],
  "parent": ObjectId("<id of parent area/crag>"),
  ...
}

In this example, the parent would be the id of Southeast Utah since the pathTokens shows:

[
  0: "USA",
  1: "Utah",
  2: "Southeast Utah",
  3: "Indian Creek"
]

@vnugent
Copy link
Contributor Author

vnugent commented Jun 20, 2023

ancestors is a CSV list of area ID's mirroring pathTokens

@siman4457
Copy link
Contributor

siman4457 commented Jun 20, 2023

Child:

_id: ObjectId("6467ab2ae622317bdb3ef74c")
area_name: "Indian Creek"
ancestors: "1db1e8ba-a40e-587c-88a4-64f5ea814b8e,ee1d37e7-dc41-5c26-a358-5d51af01f499,cbbfd7c6-5cf2-5063-8939-5f3233efa573,f166e672-4a52-56d3-94f1-14c876feb670"
pathTokens:[
  0: "USA",
  1: "Utah",
  2: "Southeast Utah",
  3: "Indian Creek"
]

Parent:

_id: ObjectId("6467ab2ae622317bdb3eef3f")
area_name: "Southeast Utah"

_id 6467ab2ae622317bdb3eef3f is not found in the ancestor list of the child. Is there some conversion between the _id and strings saved in ancestors?

I see that a mmuid is being generated from paths in genMUIDFromPaths() in src/model/MutableAreaDataSource.ts. Seems like the mmuid generated is based on the area name and not the area id.

const uuid = genMUIDFromPaths(parentPathTokens, areaName)

@vnugent
Copy link
Contributor Author

vnugent commented Jun 21, 2023

For the Areas collection, _id is auto-generated by mongo. I believe we're not using it anywhere. What we use as the primary key is metadata.area_id (it's the uuid generated from genMUIDFromPaths())

Indian Creek

ancestors: "1db1e8ba-a40e-587c-88a4-64f5ea814b8e,ee1d37e7-dc41-5c26-a358-5d51af01f499,cbbfd7c6-5cf2-5063-8939-5f3233efa573,f166e672-4a52-56d3-94f1-14c876feb670"

cbbfd7c6-5cf2-5063-8939-5f3233efa573 is area_id of South East Utah

Looking it up in Mongo Express
{ metadata.area_id: UUID('cbbfd7c6-5cf2-5063-8939-5f3233efa573') }

Screenshot 2023-06-20 at 4 57 07 PM

@vnugent vnugent assigned vnugent and unassigned siman4457 Jan 15, 2024
@vnugent vnugent changed the title Improve area aggregate (stats) updates Run area aggregate (stats) updates only for an area and its ancestors Jan 15, 2024
@vnugent vnugent closed this as completed Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants