Skip to content

Commit fcbd586

Browse files
committed
fix: sort hosts by last_updated in buckets store, so that the first host is probably the primary one
1 parent 54be44d commit fcbd586

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/stores/buckets.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ export const useBucketsStore = defineStore('buckets', {
2828
}),
2929

3030
getters: {
31-
hosts(this: State): string[] {
31+
hosts(state: State): string[] {
3232
// TODO: Include consideration of device_id UUID
33-
return _.uniq(_.map(this.buckets, bucket => bucket.hostname || bucket.data.hostname));
33+
let hosts = _.uniq(_.map(state.buckets, bucket => bucket.hostname || bucket.data.hostname));
34+
// sort by last_updated, such that the most recently updated host is first (likely the current host)
35+
hosts = _.orderBy(
36+
hosts,
37+
host => _.max(_.map(this.bucketsByHostname[host], b => b.last_updated)),
38+
['desc']
39+
);
40+
return hosts;
3441
},
3542
// Uses device_id instead of hostname
3643
devices(this: State): string[] {

0 commit comments

Comments
 (0)