Esempio n. 1
0
/*
This call deletes and creates unit-testing data.
*/
func (h *System) CreateTestData(r *http.Request, args *SystemArgs, reply *GeneralReply) error {
	c := appengine.NewContext(r)
	var err error

	// delete any previous testing data
	{
		var keys_to_delete []*datastore.Key

		REGION_UIDS_TO_DELETE := []string{"@test-san-francisco", "@test-los-angeles"}
		RESTAURANT_UIDS_TO_DELETE := []string{"@test-mcdonalds", "@test-In-N-Out", "@test-Wendys"}
		TAGS_UIDS_TO_DELETE := []string{"@test-american", "@test-french"}

		for _, uid := range REGION_UIDS_TO_DELETE {
			q := datastore.NewQuery("Tags").Filter("Uid =", uid).KeysOnly()
			keys_to_delete, err = q.GetAll(c, nil)
			checkErr(err, "DB error1")
			err = datastore.DeleteMulti(c, keys_to_delete)
			checkErr(err, "DB error2")
		}
		for _, uid := range RESTAURANT_UIDS_TO_DELETE {
			q := datastore.NewQuery("Region").Filter("Uid =", uid).KeysOnly()
			keys_to_delete, err = q.GetAll(c, nil)
			checkErr(err, "DB error3")
			err = datastore.DeleteMulti(c, keys_to_delete)
			checkErr(err, "DB error4")
		}

		for _, uid := range TAGS_UIDS_TO_DELETE {
			q := datastore.NewQuery("Restaurant").Filter("Uid =", uid).KeysOnly()
			_, err = q.GetAll(c, &keys_to_delete)
			checkErr(err, "DB error5")
			err = datastore.DeleteMulti(c, keys_to_delete)
			checkErr(err, "DB error6")
		}
		log.Printf("... cleanup done")
	}

	// re-create the data (unless this was a cleanup operation only)
	if !args.CleanupOnly {
		region1 := models.Region{Uid: "@test-san-francisco", Title: "TEST San Francisco"}
		_, err = datastore.Put(c, datastore.NewKey(c, "Region", region1.Uid, 0, nil), &region1)
		checkErr(err, "fail trying to insert")
		region2 := models.Region{Uid: "@test-los-angeles", Title: "TEST Los Angeles"}
		_, err = datastore.Put(c, datastore.NewKey(c, "Region", region2.Uid, 0, nil), &region2)
		checkErr(err, "fail trying to insert")

		restaurant1 := models.Restaurant{Uid: "@test-mcdonalds", Title: "TEST McDonalds", Tags: []string{"French Cuisine", "American"}, Regions: []string{region1.Uid}}
		_, err = datastore.Put(c, datastore.NewKey(c, "Restaurant", restaurant1.Uid, 0, nil), &restaurant1)
		checkErr(err, "fail trying to insert")
		restaurant2 := models.Restaurant{Uid: "@test-In-N-Out", Tags: []string{"American"}, Regions: []string{region1.Uid, region2.Uid}}
		_, err = datastore.Put(c, datastore.NewKey(c, "Restaurant", restaurant2.Uid, 0, nil), &restaurant2)
		checkErr(err, "fail trying to insert")
		restaurant3 := models.Restaurant{Uid: "@test-Wendys", Tags: []string{"American"}, Regions: []string{region2.Uid}}
		_, err = datastore.Put(c, datastore.NewKey(c, "Restaurant", restaurant3.Uid, 0, nil), &restaurant3)
		checkErr(err, "fail trying to insert")

		log.Printf("... creation done")
	}
	return nil
}
Esempio n. 2
0
func Clean(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	q := datastore.NewQuery("User").Limit(100)
	x := make([]User, 0, 100)
	k, err := q.GetAll(c, &x)
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	datastore.DeleteMulti(c, k)
	q2 := datastore.NewQuery("Pay").Limit(100)
	x2 := make([]Pay, 0, 100)
	k2, err2 := q2.GetAll(c, &x2)
	if err2 != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	datastore.DeleteMulti(c, k2)
	q3 := datastore.NewQuery("Trans").Limit(100)
	x3 := make([]Trans, 0, 100)
	k3, err3 := q3.GetAll(c, &x3)
	if err3 != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	datastore.DeleteMulti(c, k3)

	http.Redirect(w, r, "/admin", http.StatusFound)
}
Esempio n. 3
0
func ClearAllUsersDB(c appengine.Context) {
	q := datastore.NewQuery("User")

	var us []db.User
	// To retrieve the results,
	// you must execute the Query using its GetAll or Run methods.
	ks, err := q.GetAll(c, &us)
	if err != nil {
		fmt.Fprint(os.Stderr, "DB Error Getting All Users:"+err.Error()+"!\n\n")
		log.Fatal(err)
		return
	}

	err = datastore.DeleteMulti(c, ks)
	if err != nil {
		fmt.Fprint(os.Stderr, "DB Error Deleting All Users:"+err.Error()+"!\n\n")
		log.Fatal(err)
		return
	}

	q = datastore.NewQuery("Message")

	var ms []db.Message
	// To retrieve the results,
	// you must execute the Query using its GetAll or Run methods.
	ks, err = q.GetAll(c, &ms)
	if err != nil {
		fmt.Fprint(os.Stderr, "DB Error Getting All Messages:"+err.Error()+"!\n\n")
		log.Fatal(err)
		return
	}

	err = datastore.DeleteMulti(c, ks)
	if err != nil {
		fmt.Fprint(os.Stderr, "DB Error Deleting All Messages:"+err.Error()+"!\n\n")
		log.Fatal(err)
		return
	}

	q = datastore.NewQuery("Memo")

	var mes []db.Memo
	// To retrieve the results,
	// you must execute the Query using its GetAll or Run methods.
	ks, err = q.GetAll(c, &mes)
	if err != nil {
		fmt.Fprint(os.Stderr, "DB Error Getting All Messages:"+err.Error()+"!\n\n")
		log.Fatal(err)
		return
	}

	err = datastore.DeleteMulti(c, ks)
	if err != nil {
		fmt.Fprint(os.Stderr, "DB Error Deleting All Messages:"+err.Error()+"!\n\n")
		log.Fatal(err)
		return
	}
}
Esempio n. 4
0
func dummyData(r *http.Request, c appengine.Context) {

	// Start by wiping out the data we're about to populate
	// Delete all users
	dq := datastore.NewQuery("User").KeysOnly()
	d, _ := dq.GetAll(c, nil)
	datastore.DeleteMulti(c, d)

	// Delete all items
	dq = datastore.NewQuery("Item").KeysOnly()
	d, _ = dq.GetAll(c, nil)
	datastore.DeleteMulti(c, d)

	// Delete all comments
	dq = datastore.NewQuery("Comment").KeysOnly()
	d, _ = dq.GetAll(c, nil)
	datastore.DeleteMulti(c, d)

	// Delete all comments
	dq = datastore.NewQuery("Vote").KeysOnly()
	d, _ = dq.GetAll(c, nil)
	datastore.DeleteMulti(c, d)

	u1 := NewUser(c, "jwhardcastle", "password")
	u2 := NewUser(c, "jhutton", "password")
	u3 := NewUser(c, "rkavalsky", "password")
	u4 := NewUser(c, "teej", "password")

	i1 := NewItem(c, "Baltimore Museum of Industry, learn how a linotype works, among the city's industrial history", "This is a really cool museum that has lots of interesting displays.", "truck", "cadetblue", 39.273556, -76.601806, u1)

	i2 := NewItem(c, "OPACY: Oriole Park at Camden Yards, Home of the Baltimore Orioles", "Camden Yards is the first of the modern \"retro\" stadiums that harkens back to an earlier age of Baseball", "sun-o", "orange", 39.283501, -76.6219798, u2)

	c1 := NewComment(c, "We love going here!", u3, i2)
	c2 := NewComment(c, "typography geek heaven", u4, i1)
	c3 := NewComment(c, "Agreed! Among other things.", u1, c2)

	votables := []Votable{i1, i2, c1, c2, c3}

	for i := 0; i < 100; i++ {
		u := NewUser(c, "user"+strconv.FormatInt(int64(i), 10), "")
		for _, v := range votables {
			var value = rand.Intn(5) - 1
			if value == 0 {
				continue
			} else if value > 0 {
				value = 1
			}
			NewVote(c, u, v, int8(value))
		}
	}

	for _, v := range votables {
		v.CountVotes(c)
	}

}
Esempio n. 5
0
func (this *ArticleMetaData) Delete(ctx Context) (err error) {
	c := ctx.GAEContext
	k := datastore.NewKey(c, "Article", this.Id, 0, nil)
	err = datastore.RunInTransaction(c, func(c appengine.Context) error {
		err = datastore.Get(c, k, this)
		if err != nil {
			return err
		}
		if len(this.Tags) > 0 {
			tags := make([]Tags, len(this.Tags))
			tagsKey := make([]*datastore.Key, len(this.Tags))
			for id, tag := range this.Tags {
				tags[id].ArticleId = this.Id
				tags[id].Tag = tag
				tagId := this.Id + tag
				tagsKey[id] = datastore.NewKey(c, "Tags", tagId, 0, nil)
			}
			err = datastore.DeleteMulti(c, tagsKey)
			if err != nil {
				return err
			}
		}
		err = datastore.Delete(c, k)
		return err
	}, &datastore.TransactionOptions{XG: true})
	return err
}
Esempio n. 6
0
func DeleteTweetsByHashtag(c appengine.Context, hashtag string) error {
	c.Debugf("DeleteTweetsByHashtag")
	q := datastore.NewQuery("Tweet").Filter("Hashtag =", hashtag).Order("Created_At").Limit(300)
	var tweets []Tweet
	keys, err := q.GetAll(c, &tweets)
	if err != nil {
		c.Errorf("DeleteTweetsByHashtag failed to get: %v", err)
		return err
	}
	c.Debugf("DeleteTweetsByHashtag keys for delete: %v", keys)
	for _, tweet := range tweets {
		c.Infof("DeleteTweetsByHashtag tweet for delete: %v", tweet.Text)
	}
	if err = datastore.DeleteMulti(c, keys); err != nil {
		c.Errorf("DeleteTweetsByHashtag failed to delete tweet: %v", err)
		return err
	}

	//tweetを削除した結果、tweetが無かったら、Hashtagを削除する
	length, err := datastore.NewQuery("Tweet").Filter("Hashtag =", hashtag).Count(c)
	if err != nil {
		c.Errorf("DeleteTweetsByHashtag failed to get count: %v", err)
		return err
	}
	c.Debugf("DeleteTweetsByHashtag tweets length: %d", length)
	if length == 0 {
		c.Infof("DeleteTweetsByHashtag delete Hashtag: %s", hashtag)
		if err := DeleteHashtag(c, hashtag); err != nil {
			c.Errorf("DeleteTweetsByHashtag failed to delete hashtag: %v", err)
			return err
		}
	}
	return nil
}
Esempio n. 7
0
// DELETEs the data it returns
func (db FlightDB) ExtractTrackFragments(icao string, callsign string) ([]f.Track, error) {
	q := datastore.
		NewQuery(kTrackFragmentKind).
		Filter("Icao24 = ", icao).
		Filter("Callsign = ", callsign)

	ftfs := []f.FrozenTrackFragment{}
	if keys, err := q.GetAll(db.C, &ftfs); err != nil {
		return nil, err

	} else {
		out := []f.Track{}
		for _, ftf := range ftfs {
			t := f.Track{}
			if err := t.Base64Decode(ftf.TrackBase64); err != nil {
				return nil, err
			}
			out = append(out, t)
		}

		// OK, safe to delete !!
		if true {
			if err := datastore.DeleteMulti(db.C, keys); err != nil {
				return nil, err
			}
		}

		return out, nil
	}
}
Esempio n. 8
0
func expire(w http.ResponseWriter, r *http.Request) {
	ctx := appengine.NewContext(r)

	max := maxAge
	if age := r.FormValue("age"); age != "" {
		if ageDur, err := time.ParseDuration(age); err == nil {
			max = ageDur
		}
	}
	oldest := time.Now().Add(-max)

	q := datastore.NewQuery("paste").
		Filter("Pasted<=", oldest).
		KeysOnly()
	keys, err := q.GetAll(ctx, nil)
	if err != nil {
		ctx.Errorf("get: %s", err)
		http.Error(w, "get: "+err.Error(), http.StatusInternalServerError)
		return
	}

	ctx.Infof("Deleting %d entitites over %v old", len(keys), max)
	if err := datastore.DeleteMulti(ctx, keys); err != nil {
		ctx.Errorf("delete: %s", err)
		http.Error(w, "delete: "+err.Error(), http.StatusInternalServerError)
		return
	}

	fmt.Fprintf(w, "OK")
}
Esempio n. 9
0
func (db *Db) DeleteStoriesNotIn(ids []int) {
	allKeys := db.getAllStoryKeys()

	var keysToKeep = make([]*datastore.Key, len(ids))
	for _, id := range ids {
		keysToKeep = append(keysToKeep, db.keyForStory(id))
	}

	keysToRemove := db.findDiff(allKeys, keysToKeep)

	db.context.Debugf("Found keys to remove: %v", keysToRemove)

	if len(keysToRemove) > 0 {
		// Delete comments for story
		for _, key := range keysToRemove {
			story := new(Story)
			if err := datastore.Get(db.context, key, story); err != nil {
				db.context.Errorf("Error getting story: %v", err)
			} else {
				db.deleteComments(story.Kids)
			}
		}

		// Delete our story items
		if err := datastore.DeleteMulti(db.context, keysToRemove); err != nil {
			db.context.Errorf("Error deleting old stories: %v", err)
		}
	}
}
Esempio n. 10
0
// DelQuery will delete (from datastore and memcache) all entities of type src that matches q.
// src must be a pointer to a struct type.
func DelQuery(c PersistenceContext, src interface{}, q *datastore.Query) (err error) {
	var dataIds []*datastore.Key
	results := reflect.New(reflect.SliceOf(reflect.TypeOf(src).Elem()))
	dataIds, err = q.GetAll(c, results.Interface())
	if err = FilterOkErrors(err); err != nil {
		return
	}
	memcacheKeys := []string{}
	var el reflect.Value
	resultsSlice := results.Elem()
	for index, dataId := range dataIds {
		el = resultsSlice.Index(index)
		var k key.Key
		if k, err = gaekey.FromGAE(dataId); err != nil {
			return
		}
		el.FieldByName("Id").Set(reflect.ValueOf(k))
		if _, err = MemcacheKeys(c, el.Addr().Interface(), &memcacheKeys); err != nil {
			return
		}
		if err = runProcess(c, el.Addr().Interface(), BeforeDeleteName, nil); err != nil {
			return
		}
	}
	if err = datastore.DeleteMulti(c, dataIds); err != nil {
		return
	}
	for index, _ := range dataIds {
		el = resultsSlice.Index(index)
		if err = runProcess(c, el.Addr().Interface(), AfterDeleteName, nil); err != nil {
			return
		}
	}
	return memcache.Del(c, memcacheKeys...)
}
Esempio n. 11
0
func deleteAllItem(rw http.ResponseWriter, req *http.Request) {
	// To access datastore and to log
	c := appengine.NewContext(req)
	c.Infof("deleteAll()")

	// Delete root entity after other entities
	r := 0
	pKey := datastore.NewKey(c, ItemKind, ItemRoot, 0, nil)
	if keys, err := datastore.NewQuery(ItemKind).KeysOnly().GetAll(c, nil); err != nil {
		c.Errorf("%s", err)
		r = 1
	} else if err := datastore.DeleteMulti(c, keys); err != nil {
		c.Errorf("%s", err)
		r = 1
	} else if err := datastore.Delete(c, pKey); err != nil {
		c.Errorf("%s", err)
		r = 1
	}

	// Return status. WriteHeader() must be called before call to Write
	if r == 0 {
		rw.WriteHeader(http.StatusOK)
	} else {
		http.Error(rw, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
	}
}
Esempio n. 12
0
func Refresh(w http.ResponseWriter, r *http.Request) {
	if extendMethod(r) == "GET" {
		var account Account
		q := datastore.NewQuery("Account")
		for t := q.Run(c); ; {
			_, err := t.Next(&account)
			if err == datastore.Done {
				break
			}
			if account.Verified() {
				if account.Version() == 2 {
					account.prepareOAuth2Connection(r)
				}
				switch account.Name {
				case "github":
					account.GetGithubUpdates(r)
				case "linkedin":
					account.GetLinkedInUpdates(r)
				case "twitter":
					account.GetTwitterUpdates(r)
				case "xing":
					account.GetXingUpdates(r)
				}
			}
		}
		q = datastore.NewQuery("Status").Order("-Created").Offset(100).KeysOnly()
		keys, err := q.GetAll(c, nil)
		if err == nil && len(keys) > 0 {
			datastore.DeleteMulti(c, keys)
		}
	}
	pageTemplate, _ := template.ParseFiles("templates/manage/refresh.txt")
	w.Header().Set("Content-Type", "text/plain; charset=utf-8")
	pageTemplate.Execute(w, map[string]interface{}{"notice": session.Flashes()})
}
Esempio n. 13
0
func deleteAll(ctx appengine.Context, kind string) error {
	keys, err := datastore.NewQuery(kind).KeysOnly().GetAll(ctx, nil)
	if err != nil {
		return err
	}
	return datastore.DeleteMulti(ctx, keys)
}
Esempio n. 14
0
func batchDestroy(c appengine.Context, w http.ResponseWriter, r *http.Request) {
	keyStr := []string{}
	z, err := gzip.NewReader(r.Body)
	maybePanic(err)
	d := json.NewDecoder(z)
	maybePanic(d.Decode(&keyStr))
	c.Infof("Got %v keys to destroy", len(keyStr))

	keys := []*datastore.Key{}
	for _, k := range keyStr {
		key, err := datastore.DecodeKey(k)
		if err != nil {
			c.Errorf("Error decoding key: %v: %v", k, err)
			http.Error(w, err.Error(), 500)
			return
		}
		keys = append(keys, key)
	}

	err = datastore.DeleteMulti(c, keys)
	if err != nil {
		c.Infof("Error deleting things: %v", err)
		http.Error(w, err.Error(), 500)
		return
	}

	w.WriteHeader(204)
}
Esempio n. 15
0
// deleteList deletes the list with the id given in the url if the user is
// logged in and is the creator of the list.
func deleteList(w io.Writer, r *http.Request) error {
	c := appengine.NewContext(r)

	// Decode the list id in the URL and check the current user is the creator.
	key, creator, err := decode(mux.Vars(r)["list"])
	if err != nil {
		return err
	}
	if creator != user.Current(c).Email {
		return appErrorf(http.StatusForbidden, "only %v can do this", creator)
	}

	// Delete all tasks in the list and the list itself in a transaction.
	return datastore.RunInTransaction(c, func(c appengine.Context) error {
		// Find all the tasks in the list.
		taskKeys, err := datastore.NewQuery(taskKind).
			Ancestor(key).KeysOnly().GetAll(c, nil)
		if err != nil {
			return fmt.Errorf("get all tasks in list: %v", err)
		}

		// Delete all the tasks in the list.
		err = datastore.DeleteMulti(c, taskKeys)
		if err != nil {
			return fmt.Errorf("delete all tasks in list: %v", err)
		}

		// Delete the list itself.
		return datastore.Delete(c, key)
	}, nil)
}
Esempio n. 16
0
// remove expired sessions in the datastore. you can call this function
// from a cron job.
//
// sample handler config in app.yaml:
// handlers:
// - url: /tasks/removeExpiredSessions
//   script: _go_app
//   login: admin
// - url: /.*
//   script: _go_app
//
// handler registration code:
// http.HandleFunc("/tasks/removeExpiredSessions", removeExpiredSessionsHandler)
//
// sample handler:
// func removeExpiredSessionsHandler(w http.ResponseWriter, r *http.Request) {
//	c := appengine.NewContext(r)
//	gaesessions.RemoveExpiredDatastoreSessions(c, "")
// }
//
// sample cron.yaml:
// cron:
// - description: expired session removal job
//   url: /tasks/removeExpiredSessions
//   schedule: every 1 minutes
func RemoveExpiredDatastoreSessions(c appengine.Context, kind string) error {
	keys, err := findExpiredDatastoreSessionKeys(c, kind)
	if err != nil {
		return err
	}
	return datastore.DeleteMulti(c, keys)
}
Esempio n. 17
0
func developerHandler(w io.Writer, r *http.Request) error {
	ctx := appengine.NewContext(r)

	if r.Method == "GET" {
		p, err := NewPage(ctx, "developer", nil)
		if err != nil {
			return fmt.Errorf("create developer page: %v", err)
		}
		return p.Render(w)
	}
	if r.Method != "POST" {
		return fmt.Errorf("unsupported method %v", r.Method)
	}

	switch {
	case r.FormValue("deleteall") == "yes":
		kind := r.FormValue("kind")
		keys, err := datastore.NewQuery(kind).KeysOnly().GetAll(ctx, nil)
		if err != nil {
			return fmt.Errorf("get keys to delete: %v", err)
		}
		if err := datastore.DeleteMulti(ctx, keys); err != nil {
			return fmt.Errorf("delete keys: %v", err)
		}
	case len(r.FormValue("announcement")) > 0:
		a := conf.NewAnnouncement(r.FormValue("announcement"))
		if err := a.Save(ctx); err != nil {
			return err
		}
	}
	return RedirectTo("/developer")
}
Esempio n. 18
0
File: gc.go Progetto: h8liu/golang
func handleGC(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)

	// Delete closed CLs that haven't been modified in 168 hours (7 days).
	cutoff := time.Now().Add(-168 * time.Hour)
	q := datastore.NewQuery("CL").
		Filter("Closed =", true).
		Filter("Modified <", cutoff).
		Limit(100).
		KeysOnly()
	keys, err := q.GetAll(c, nil)
	if err != nil {
		c.Errorf("GetAll failed for old CLs: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	if len(keys) == 0 {
		return
	}

	if err := datastore.DeleteMulti(c, keys); err != nil {
		c.Errorf("DeleteMulti failed for old CLs: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	c.Infof("Deleted %d old CLs", len(keys))
}
Esempio n. 19
0
func maybeGarbageCollect(c appengine.Context) {
	var randByte [1]byte
	_, err := io.ReadFull(rand.Reader, randByte[:])
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error reading random byte: %s\n", err)
		return
	}

	if randByte[0] >= 2 {
		return
	}

	// Every one in 128 insertions we'll clean out expired postings.
	q := datastore.NewQuery("Posting").Order("-Time").Limit(256)
	var toDelete []*datastore.Key
	for t := q.Run(c); ; {
		var p Posting
		key, err := t.Next(&p)
		if err == datastore.Done {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "Error from query: %s\n", err)
			break
		}
		if !p.Expired() {
			break
		}
		toDelete = append(toDelete, key)
	}
	if err := datastore.DeleteMulti(c, toDelete); err != nil {
		fmt.Fprintf(os.Stderr, "Error from multi-delete: %s\n", err)
	}
}
Esempio n. 20
0
func DeleteFolder(c appengine.Context, ref FolderRef) error {
	folderKey, err := ref.key(c)
	if err != nil {
		return err
	}

	// Get a list of relevant subscriptions
	q := datastore.NewQuery("Subscription").Ancestor(folderKey).KeysOnly().Limit(defaultBatchSize)
	subscriptionKeys, err := q.GetAll(c, nil)

	if err != nil {
		return err
	}

	// Delete folder & subscriptions
	if err := datastore.Delete(c, folderKey); err != nil {
		c.Errorf("Error deleting folder: %s", err)
		return err
	}

	if subscriptionKeys == nil {
		// No subscriptions; nothing more to do
		return nil
	}

	if err := datastore.DeleteMulti(c, subscriptionKeys); err != nil {
		c.Errorf("Error deleting subscriptions: %s", err)
		return err
	}

	return nil
}
Esempio n. 21
0
func UpdateMedia(c appengine.Context, entryKey *datastore.Key, entry *rss.Entry) error {
	// Find and remove any existing media
	q := datastore.NewQuery("EntryMedia").Filter("Entry =", entryKey).KeysOnly().Limit(40)
	if entryMediaKeys, err := q.GetAll(c, nil); err != nil {
		return err
	} else if len(entryMediaKeys) > 0 {
		if datastore.DeleteMulti(c, entryMediaKeys); err != nil {
			return err
		}
	}

	batchWriter := NewBatchWriter(c, BatchPut)

	// Add media
	for _, media := range entry.Media {
		entryMediaKey := datastore.NewIncompleteKey(c, "EntryMedia", nil)
		entryMedia := EntryMedia{
			URL:   media.URL,
			Type:  media.Type,
			Entry: entryKey,
		}

		if err := batchWriter.Enqueue(entryMediaKey, &entryMedia); err != nil {
			c.Errorf("Error queueing media for batch write: %s", err)
			return err
		}
	}

	if err := batchWriter.Flush(); err != nil {
		c.Errorf("Error flushing batch queue: %s", err)
		return err
	}

	return nil
}
Esempio n. 22
0
func (builder *stepsBuilder) DeleteBatchFromDatastore(context appengine.Context) stream.EachFn {
	return func(data stream.T) {
		if err := datastore.DeleteMulti(context, data.(*DatastoreBatch).Keys); err != nil {
			panic(err)
		}
	}
}
Esempio n. 23
0
// DeleteMulti is a batched version of Delete.
func DeleteMulti(c appengine.Context, key []*datastore.Key) error {
	errm := memcache.DeleteMulti(c, encodeKeys(key))
	errd := datastore.DeleteMulti(c, key)
	if errd != nil {
		return errd
	}
	return errm
}
Esempio n. 24
0
func (authen *Authen) DeleteUsers(userids []string) error {
	var keys []*datastore.Key = make([]*datastore.Key, len(userids))
	for i, id := range userids {
		id = strings.ToLower(id)
		keys[i] = datastore.NewKey(authen.c, AUTHEN, id, 0, nil)
	}
	return datastore.DeleteMulti(authen.c, keys)
}
Esempio n. 25
0
func (s *Scale) DeleteScale(c appengine.Context) (err error) {
	err = datastore.DeleteMulti(c, getIntKeys(c, "Valuation", s.ValuationIDs...))
	if err != nil {
		return
	}

	return datastore.Delete(c, datastore.NewKey(c, "Scale", "", s.ID, nil))
}
func deleteDoneTodos(c appengine.Context) error {
	return datastore.RunInTransaction(c, func(c appengine.Context) error {
		ks, err := datastore.NewQuery("Todo").KeysOnly().Ancestor(defaultTodoList(c)).Filter("Done=", true).GetAll(c, nil)
		if err != nil {
			return err
		}
		return datastore.DeleteMulti(c, ks)
	}, nil)
}
Esempio n. 27
0
func DelRooms(c appengine.Context, rooms []Room) error {
	keys := make([]*datastore.Key, 0)
	for _, room := range rooms {
		keys = append(keys, datastore.NewKey(c, "Room", room.Name, 0, nil))
	}
	c.Debugf("Deleting Rooms: %+v", keys)
	err := datastore.DeleteMulti(c, keys)
	return err
}
Esempio n. 28
0
func clearKind(c appengine.Context, kind string) {
	q := datastore.NewQuery(kind).KeysOnly()
	keys, err := q.GetAll(c, nil)
	if err != nil {
		panic(&appError{err, "Failed to fetch all " + kind, 500})
	}
	if err := datastore.DeleteMulti(c, keys); err != nil {
		panic(&appError{err, "Failed to delete all " + kind, 500})
	}
}
Esempio n. 29
0
func handleWipe(w http.ResponseWriter, r *http.Request, c *Context) {
	for typeName, _ := range types {
		q := datastore.NewQuery(typeName).KeysOnly()
		keys, err := q.GetAll(c.Aec(), nil)
		CheckError(err)
		CheckError(datastore.DeleteMulti(c.Aec(), keys))
	}
	c.DeleteSession()
	RedirectWithMessage(w, r, "/", "Datastore has been wiped.")
}
Esempio n. 30
0
// DeleteAllItems deletes all items from datastore
func DeleteAllItems(c appengine.Context) error {
	q := datastore.NewQuery("Item").KeysOnly()

	k, err := q.GetAll(c, nil)
	if err != nil {
		return nil
	}

	return datastore.DeleteMulti(c, k)
}