[lxc-devel] [lxd/master] lxd/containers: Speed up simple snapshot list

stgraber on Github lxc-bot at linuxcontainers.org
Tue Apr 30 21:48:47 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190430/0e0519cb/attachment.bin>
-------------- next part --------------
From be759747357b40562b1f5760fb86aa426fbde298 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 30 Apr 2019 17:29:51 -0400
Subject: [PATCH] lxd/containers: Speed up simple snapshot list
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: St├ęphane Graber <stgraber at ubuntu.com>
---
 lxd/container_snapshot.go | 40 ++++++++++++++++++++++-----------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/lxd/container_snapshot.go b/lxd/container_snapshot.go
index bcc77a984b..37230484ee 100644
--- a/lxd/container_snapshot.go
+++ b/lxd/container_snapshot.go
@@ -33,31 +33,37 @@ func containerSnapshotsGet(d *Daemon, r *http.Request) Response {
 	}
 
 	recursion := util.IsRecursionRequest(r)
-
-	c, err := containerLoadByProjectAndName(d.State(), project, cname)
-	if err != nil {
-		return SmartError(err)
-	}
-
-	snaps, err := c.Snapshots()
-	if err != nil {
-		return SmartError(err)
-	}
-
 	resultString := []string{}
 	resultMap := []*api.ContainerSnapshot{}
 
-	for _, snap := range snaps {
-		_, snapName, _ := containerGetParentAndSnapshotName(snap.Name())
-		if !recursion {
-			if snap.Project() == "default" {
+	if !recursion {
+		snaps, err := d.cluster.ContainerGetSnapshots(project, cname)
+		if err != nil {
+			return SmartError(err)
+		}
+
+		for _, snap := range snaps {
+			_, snapName, _ := containerGetParentAndSnapshotName(snap)
+			if project == "default" {
 				url := fmt.Sprintf("/%s/containers/%s/snapshots/%s", version.APIVersion, cname, snapName)
 				resultString = append(resultString, url)
 			} else {
-				url := fmt.Sprintf("/%s/containers/%s/snapshots/%s?project=%s", version.APIVersion, cname, snapName, snap.Project())
+				url := fmt.Sprintf("/%s/containers/%s/snapshots/%s?project=%s", version.APIVersion, cname, snapName, project)
 				resultString = append(resultString, url)
 			}
-		} else {
+		}
+	} else {
+		c, err := containerLoadByProjectAndName(d.State(), project, cname)
+		if err != nil {
+			return SmartError(err)
+		}
+
+		snaps, err := c.Snapshots()
+		if err != nil {
+			return SmartError(err)
+		}
+
+		for _, snap := range snaps {
 			render, _, err := snap.Render()
 			if err != nil {
 				continue


More information about the lxc-devel mailing list