How do i delete the whole table (entity) thereby freeing all the memory in google app engine where the entity is defined as follows:
class Message(db.Model):
name=db.StringProperty(required=True)
message=db.StringProperty(required=True)
created=db.DateTimeProperty(auto_now_add=True)
I am working in python...
try this:
db.delete(Message.all())
One way to do this (especially if you're model has a large number of entities) is to go to the 'Datastore Admin' tab of the app engine console. Here you can select a kind and choose to delete all entities (app engine starts a mapreduce job to delete all the entities).
This is useful when you have enough entities that doing
db.delete(Message.all())
will timeout/take way too long.
Related
I am new to Google App Engine development. We have developed application with android and Google App Engine.We tried to delete all data but write operations became 100% and we can not simply delete further records. How can we manage to delete the data without exceeding 100%.
Can someone please explain us so we can follow the steps.
Thanks,
Prashant
You simply cannot delete records without accounting it for in the quota.
Ref: https://cloud.google.com/appengine/pricing#costs-for-datastore-calls
Entity Delete (per entity) --> 2 writes + 2 writes per indexed property value + 1 write per composite index value
So if you are in free-quota, you cannot delete or write any further, without enable billing.
Work around
Google allows 25 free app-engine projects to each user id. Create a new project and upload the old project code to new project id. If your daily traffic is within the free quota, you can use it as long as you want.
I'm making a good progress using Web2py and Google App Engine, but now I have to decide how to store images without waste GAE resources!
I have a "table" were I store products.
Each product can have a maximum of 12 picutes.
When I request the product page, lets say:
/product/7484/
I need only the product informations, without the pictures, but GAE engine get all fields from datastore! I thought that using Google App Engine Projection Queries, this could be solved and I would only fetch the fields I need!
Is that possible with Web2py or will I have to change my database to store imagens on another "table"?
I only will need fetch each picute field when they get requested by browser... but now, each picture requested cause the whole product entity being fetched from database!
We have it as an experimental feature in trunk. Perhaps you can help us test it. Nothing special to do just the usual:
db(query).select(db.table.field1, db.table.field2, etc.)
unless the query selects a single record by id, the arguments of select are converted into a projection query. Unfortunately GAE does not support projection for get_by_id().
Thanks to Christian (howesc) who pulled this off within 24 hrs from you requesting the feature. Please join us on the web2py google group if you can help testing.
I'd like to re-open Deleted Datastore entries reappear as a registered user. Can the old question be deleted?
I'll try to be more specific this time. I'm experiencing the following problem:
Initially I put N entities of the same kind into the Datastore like that:
datastore_entity = MyModel(model_property=property_value)
datastore_entity.put()
Afterwards I delete them. I have used the Datastore Admin interface as well as a self-defined handler for the mapreduce library in order to do so. The deleted entities do not appear neither in the Datastore viewer nor in the Datastore Admin view.
When I put even just one new single entity of this kind into the Datastore, the old Datastore entities reappear in the Datastore Admin view while the new entity does not (judging by the number of entities). On the contrary, the Datastore viewer correctly reflects the Datastore state. A query also returns only the newly created entity.
There are no tasks at the time the new entity is being put into the Datastore.
I'm also not encountering this problem on my local machine where I'm using the --clean_datastore option when starting the server.
The Datastore Admin and Datastore Statistics are not "live". The Datastore viewer offers a live view.
Check "Entity statistics last updated..." and you will notice the difference.
If the old entities are not visible in the Datastore viewer - no need to worry. Eventually the statistics will be updated.
I'd like to re-open Deleted Datastore entries reappear as a registered user. Can the old question be deleted?
I'll try to be more specific this time. I'm experiencing the following problem:
Initially I put N entities of the same kind into the Datastore like that:
datastore_entity = MyModel(model_property=property_value)
datastore_entity.put()
Afterwards I delete them. I have used the Datastore Admin interface as well as a self-defined handler for the mapreduce library in order to do so. The deleted entities do not appear neither in the Datastore viewer nor in the Datastore Admin view.
When I put even just one new single entity of this kind into the Datastore, the old Datastore entities reappear in the Datastore Admin view while the new entity does not (judging by the number of entities). On the contrary, the Datastore viewer correctly reflects the Datastore state. A query also returns only the newly created entity.
There are no tasks at the time the new entity is being put into the Datastore.
I'm also not encountering this problem on my local machine where I'm using the --clean_datastore option when starting the server.
The Datastore Admin and Datastore Statistics are not "live". The Datastore viewer offers a live view.
Check "Entity statistics last updated..." and you will notice the difference.
If the old entities are not visible in the Datastore viewer - no need to worry. Eventually the statistics will be updated.
In Singapore, we are teaching students python using Singpath (singpath.appspot.com). In addition to letting students practice writing software in python, we would like to familiarize students with the google.appengine.ext.db API used to access big table.
What is the easiest way to modify db.Model settings in an App Engine app so that any puts or gets access a local, temporary datastore rather than writing to big table? I'm trying to do something similar to how gaeunit creates a new temporary datastore each time unit tests are run.
from google.appengine.ext import db
import logging
class MyModel(db.Model):
name = db.StringProperty()
#Configure a temp datastore to be updated instead of bigtable.
m = MyModel()
m.put() #shouldn't update bigtable
result = MyModel.all() #should fetch from temp datastore
logging.info("There were %s models saved", result.count())
You can certainly do this in the dev server by creating a new stub datastore when you want, like gaeunit. I don't think the concept really transfers to the production environment, though. A temporary datastore would have to have some kind of backing store, either the real datastore or memcache. AFAIK there's no built-in support for either.
An alternative would be to use the real datastore with some sandboxing.
You could override db.Model.kind to prefix a session ID:
#classmethod
def kind(cls):
return "%s_%s" % (SESSION_ID, cls.__name__)
This would give you basic namespacing for user-created entities.
If you have a session entity, you could populate it as the parent entity on any query that does not already specify one. This would force all of your user's entities into one entity group.
In either case, at the start of the session you could schedule a task to run later that would clean up entities that the user created.