GAE Random Fetch entity

Source: Internet
Author: User
Tags minimalist design

Sometimes we need to randomly acquire data records (entities), such as the implementation of "random articles" in a blog program.

At present, GAE does not have APIs to directly access random entities, to achieve such a demand we can only find a way to do it:-)

The issue was also mentioned on StackOverflow, as summarized below: Generate and store a random number on your entities as for you create them, then pick a random Number and look through (via a query) for the "closet record" (s) to it. Implement some mechanism to ensure your entity IDs are "densely" populated, then fetch within the known range using keys. Periodically generate random lists of the entities and return entities from those lists. This could take the form of a stack that entities are popped off, or as actual lists that are.

At present, B3log Solo in the processing of "random reading" on the method is one, that is, in each article entity to add a property to save 0-1 of the random floating-point number.

Generates a random article 0-1 of the random number (mid) as a query condition, with this query condition as the boundary (0 <= mid <=1) to filter the entity saved random value properties.

This method can basically achieve a random effect, in order to make the random effect more dynamic, we can consider to update the article entity random floating-point values frequently: when accessing an article (that is, updating the article's random floating-point values when the article is browsed) Background timed task (gets a certain number of random articles and then updates their random floating-point values) when the user makes a fuss update

Plus the above treatment, the random effect is better:-)

This article is to use the B3log Solo from the minimalist design of the art to synchronize the publication of the original address: http://88250.b3log.org/get-gae-random-entities.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.