GraphQL

Recently, I read some articles about GraphQL and it looks quite interesting. After further reading, I came up this post.

What is GraphQL?

GraphQL is a query language for API, and a server-side runtime for executing queries using a type system you define for your data.

Read More

Django Database Performance Optimization

As a project grows, our database size turns larger and we may experience longer waiting time when query an API.
Then it is time to make some performance optimizations. DB query is one of the items that causes performance reduction.

Read More

Python magic methods

  • __new__() and __init__()

__new__() is always called before __init__().
Use __new__ when you need to control the creation of a new instance.
Use __init__ when you need to control initialization of a new instance.

Read More

Django Unit Test

Why unit test?

Tests can let us avoid breaking things when doing the refactoring.

Read More

Django-rest-framework View

In most cases, we write view functions in views.py. However, we may write many duplicate codes such as post_list = Post.objects.all() and post = get_object_or_404(Post, pk = pk). In order to solve this problem, Django provides us generic view class. There are two common class we can inherite. One is ListView, the other is DetailView.

Read More

Database transaction

A database transaction is a series of SQL commands.

Database transaction properties: ACID

Atomicity

A transaction must be an atomatic unit of work; either all of SQL commands are performed, or none of them is performed.

Read More

HTTP Request/Response Process

What happened after you enter a URL into the web browser? How does a complete HTTP request/response process look like?

Step 1: Parsing the URL to a IP address

First of all, the url typed on the web browser will transfer into a IP address. How does the url map to the related IP address? The details are as follow.

Read More

Indexing in MySQL Database

In order to increase speed of searching a record in the database, we usually create indice. Actually, indexing is a kind of data structure.
For finding a specific element in a table, the common way is to search one by one. However, its time complexity is O(n). A wiser way is to use Binary Search Tree whose time complexity is O(log(n)). Sounds great? Here is the thing, index files store in external memory so swithching from one block (node) to another block is time comsuming. The more nodes a tree has, the more time it takes to deal with I/O operation for the disk. Our goal is to reduce the height of the tree(or the number of nodes), so that B-trees and B+ trees are decent choices. It is because multiple keys are able to store in one node, so the height of the tree drop down rapidly.

Read More

Hello World

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Read More