This occurs in Nomad UI, an open source ember app: https://github.com/hashicorp/nomad/tree/master/ui
Fetching related data in the right order under unknown circumstances will push a copy of an existing record instead of updating the existing record.
- Start on the clients page This will fetch /nodes and /nodes/node-1 and /node/node-1/allocations To display the list nodes, the details for each node, and the count of allocations for each node.
- Go to the jobs page This will fetch /jobs to list all jobs
- Go to job-1 This will fetch a lot of related data for the job, including /job/job-1/allocations. The allocations for the job overlap with the allocations for the node, since allocations belong to a job and run on a node.
- Inspect the state of node-1 It will now have one more allocation than before, due to the overlapping allocation in the /job/job-1/allocations reponse appending to the node allocations hasMany rather than updating it.
- Inspect the state of peekAll('allocation') The store has the correct number of allocations. The errant duplicate is local to only the node's relationship state.
- Jobs have many properties, including a hasMany of allocations https://github.com/hashicorp/nomad/blob/master/ui/app/models/job.js
- The job serializer overrides extractRelationships to wire the hasMany up to the url shown above https://github.com/hashicorp/nomad/blob/a6a04b3cac09c8737fe5350283dd2ecc8f3f9d96/ui/app/serializers/job.js#L51-L84
- Nodes are modeled similarly https://github.com/hashicorp/nomad/blob/master/ui/app/models/node.js
- Node have the same behavior in the serializerhttps://github.com/hashicorp/nomad/blob/a6a04b3cac09c8737fe5350283dd2ecc8f3f9d96/ui/app/serializers/node.js#L21-L34
- Allocations have a belongsTo for job and node https://github.com/hashicorp/nomad/blob/a6a04b3cac09c8737fe5350283dd2ecc8f3f9d96/ui/app/models/allocation.js#L22-L23
- All nodes are fetched in the clients route https://github.com/hashicorp/nomad/blob/master/ui/app/routes/clients.js
- Changes to the nodes are watched (long-polled) in the clients.index route, but this has been ruled out as the cause of failure https://github.com/hashicorp/nomad/blob/master/ui/app/routes/clients/index.js
- The client-node-row component reloads the node to get the detail information. It also fetches allocations by way of the template. Finally it watches allocations https://github.com/hashicorp/nomad/blob/master/ui/app/components/client-node-row.js
- All jobs are fetched in the jobs route https://github.com/hashicorp/nomad/blob/master/ui/app/routes/jobs.js
- Changes to the jobs are watched (long-polled) in the jobs.index route https://github.com/hashicorp/nomad/blob/master/ui/app/routes/jobs/index.js
- The jobs.job route fetchs the job's allocations in the model hook https://github.com/hashicorp/nomad/blob/master/ui/app/routes/jobs/job.js#L21
- The jobs.job.index route watches (long-polls) multiple job relationships https://github.com/hashicorp/nomad/blob/master/ui/app/routes/jobs/job/index.js