Home  >  Article  >  WeChat Applet  >  The difference between small program cloud development and non-cloud development

The difference between small program cloud development and non-cloud development

Guanhui
GuanhuiOriginal
2020-05-29 17:50:3922511browse

The difference between small program cloud development and non-cloud development

The difference between Mini Program cloud development and non-cloud development

1. Cloud development does not require building a server. Mini Program Cloud provides a free basic version , if it is non-cloud development, you need to build a server.

2. Cloud development projects can be launched quickly, and can be used to add, delete, modify, and query databases and store objects without relying on external cloud servers.

The Pitfalls of WeChat Mini Program Cloud Development

1. The Basic Edition CDN Traffic Is Too Little

In my case In a recent project, during the development and testing period alone, it took 765MB to upload/download the original quality pictures of the album (four to five days). At that time, I realized the seriousness of the matter, because after the project went online It needs to be used by hundreds of users every day. If it is like what I tested, the CDN traffic may be used up in two days. Once the CDN traffic is used up, upgrading the configuration will cost at least 30 yuan a month. At this price, you can buy a good object storage service outside.

But fortunately, I discovered this problem relatively early and controlled the quality of the uploaded pictures in time. The program automatically compresses each picture uploaded. Each picture is about 200kb. It has only been consumed since it was officially used. Received about 1mb of CDN traffic. (The average daily active users are about 60)

2. There are many restrictions on cloud databases

I think this pitfall is the deepest one for me. There are two limitations of cloud databases. The first aspect is the limit on the number of data items obtained by the mini program. The second aspect is cloud database read and write permission restrictions.

(1) Mini program read limit

The mini program directly requests the database, and can read up to 20 pieces of data each time

Use cloud functions to request the database, and then Trigger the cloud function through the applet, and read up to 100 pieces of data each time

If more than 100 pieces of data need to be requested each time, you need to use skip to request in batches and then combine them. The specific operation can be viewed Official documentation or other blogs.

(2) Cloud database read and write permission restrictions

Before talking about this pitfall, let me say that the mini program cloud database is a non-relational database and cannot use joint queries with foreign keys and internal keys. (Irrelevant to the context, not mentioned in this article)

The most open permission of the cloud database is: readable by all users, only the creator can change it.

That is to say, if you create a record, others cannot modify or delete it, which leads to a series of problems. Here is an example of my actual project.

eg: There is a multi-seat study room for users to book. Users can choose a usage time for each reservation. After this time is over, the seat can be booked again by others.

A simple scenario. Under normal logic, the study room table in our database should have these three main fields. Study room identification (r_id), study room expiration time (r_date), Whether the study room can be reserved (r_flag).

When a user chooses to reserve a study room, I only need to determine whether the r_flag of the study room is true. If it is true, the user can reserve it. After the reservation is successful, r_date is refreshed and r_flag is set to false. Can.

However, the most open permissions for the cloud database provided by Mini Program Cloud Development are readable by all users and can only be changed by the creator. As a result, the above logic does not work. We need more complex logic to implement this function.

What I did at the time was: submit a piece of data every time a user makes a reservation for a study room, and put all the reservation data for each study room into stacks in order of time, with the latest reservation on top. In this way, the next time someone makes a reservation, they only need to compare whether the r_date of the top data is reached to determine whether the study room can currently be reserved. Implement an overwrite and delete function without modifying the record.

3. There are many restrictions on opening to the outside world

A normal mini program project will generally be equipped with a backend management system. This backend management system and the mini program share a database to manage data. Since the cloud database that comes with the mini program cloud development is inside the mini program, if the outside wants to access this database, a slightly complicated process is required:

First use the official interface to obtain the calling credentials, and then use the specified credentials through this credentials Interface to add, delete, modify and check the database. In addition, the resources consumed in this process are also included in the basic configuration, and 50,000 requests are made online every day.

Recommended tutorials: "Small Program Development" "PHP Tutorial"

The above is the detailed content of The difference between small program cloud development and non-cloud development. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn