Example #1
0
func (fileStore *blobstoreFileStore) RemoveFiles(fileKeys []string) {
	keys := make([]appengine.BlobKey, len(fileKeys))
	for i := 0; i < len(fileKeys); i++ {
		keys[i] = appengine.BlobKey(fileKeys[i])
	}

	blobstore.DeleteMulti(fileStore.context, keys)
}
Example #2
0
func DeleteBlobs(c mpg.Context, w http.ResponseWriter, r *http.Request) {
	ctx := appengine.Timeout(c, time.Minute)
	q := datastore.NewQuery("__BlobInfo__").KeysOnly()
	it := q.Run(ctx)
	wg := sync.WaitGroup{}
	something := false
	for _i := 0; _i < 20; _i++ {
		var bk []appengine.BlobKey
		for i := 0; i < 1000; i++ {
			k, err := it.Next(nil)
			if err == datastore.Done {
				break
			} else if err != nil {
				c.Errorf("err: %v", err)
				continue
			}
			bk = append(bk, appengine.BlobKey(k.StringID()))
		}
		if len(bk) == 0 {
			break
		}
		go func(bk []appengine.BlobKey) {
			something = true
			c.Errorf("deleteing %v blobs", len(bk))
			err := blobstore.DeleteMulti(ctx, bk)
			if err != nil {
				c.Errorf("blobstore delete err: %v", err)
			}
			wg.Done()
		}(bk)
		wg.Add(1)
	}
	wg.Wait()
	if something {
		taskqueue.Add(c, taskqueue.NewPOSTTask("/tasks/delete-blobs", nil), "")
	}
}
Example #3
0
var clean = apiutil.Error(apiutil.Json(apiutil.Admin(
	func(w http.ResponseWriter, r *http.Request) error {
		c := appengine.NewContext(r)
		q := datastore.NewQuery(painting.Kind).Project("Image")

		var paintings []*painting.Painting
		keys, err := q.GetAll(c, &paintings)
		if err != nil {
			return err
		}

		var blobKeys []appengine.BlobKey
		for _, p := range paintings {
			if p.Image.BlobKey != appengine.BlobKey(" ") {
				blobKeys = append(blobKeys, p.Image.BlobKey)
			}
		}
		err = blobstore.DeleteMulti(c, blobKeys)
		if err != nil {
			return err
		}

		datastore.DeleteMulti(c, keys)
		if err != nil {
			return err
		}

		return nil
	})))