switch layers to slice.

This commit is contained in:
Miroslav Šedivý
2022-01-07 21:04:05 +01:00
parent 50d10bd097
commit d13542b322
5 changed files with 21 additions and 12 deletions
+2 -2
View File
@@ -548,8 +548,8 @@ components:
format: datetime
example: "2021-03-07T21:56:34Z"
layers:
type: object
additionalProperties:
type: array
items:
$ref: '#/components/schemas/PullLayer'
status:
type: array
+2 -2
View File
@@ -195,10 +195,10 @@ export interface PullStatus {
'started'?: string;
/**
*
* @type {{ [key: string]: PullLayer; }}
* @type {Array<PullLayer>}
* @memberof PullStatus
*/
'layers'?: { [key: string]: PullLayer; };
'layers'?: Array<PullLayer>;
/**
*
* @type {Array<string>}
+1 -1
View File
@@ -15,7 +15,7 @@
Pull neko images
</v-card-title>
<v-card-text>
<template v-if="status.active && status.layers && Object.keys(status.layers).length > 0">
<template v-if="status.active && status.layers && status.layers.length > 0">
<pre v-for="layer in status.layers" :key="layer.id">{{ layer.id }} {{ layer.status }}{{ layer.progress && ' ' + layer.progress }}</pre>
<br />
</template>
+11 -2
View File
@@ -18,6 +18,7 @@ type PullConfig struct {
mu sync.Mutex
cancel func()
status types.PullStatus
layers map[string]int
}
func (pull *PullConfig) TryInitialize(cancel func()) bool {
@@ -35,10 +36,12 @@ func (pull *PullConfig) TryInitialize(cancel func()) bool {
pull.status = types.PullStatus{
Active: true,
Started: &now,
Layers: map[string]types.PullLayer{},
Layers: []types.PullLayer{},
Status: []string{},
}
pull.layers = map[string]int{}
return true
}
@@ -120,7 +123,13 @@ func (manager *RoomManagerCtx) PullStart(request types.PullStart) error {
}
if layer.ProgressDetail != nil {
manager.pull.status.Layers[layer.ID] = layer
// map layer id to slice index
if index, ok := manager.pull.layers[layer.ID]; ok {
manager.pull.status.Layers[index] = layer
} else {
manager.pull.layers[layer.ID] = len(manager.pull.layers)
manager.pull.status.Layers = append(manager.pull.status.Layers, layer)
}
} else {
manager.pull.status.Status = append(
manager.pull.status.Status,
+5 -5
View File
@@ -262,11 +262,11 @@ type PullLayer struct {
}
type PullStatus struct {
Active bool `json:"active"`
Started *time.Time `json:"started"`
Layers map[string]PullLayer `json:"layers"`
Status []string `json:"status"`
Finished *time.Time `json:"finished"`
Active bool `json:"active"`
Started *time.Time `json:"started"`
Layers []PullLayer `json:"layers"`
Status []string `json:"status"`
Finished *time.Time `json:"finished"`
}
type RoomManager interface {