我将Firebase Realtime Database与Django使用pyrebase一起使用。当我在同一视图中进行多个查询时,需要很长时间才能检索数据。
我尝试一次全部获取数据库,这使加载速度大大加快,但是数据库有一个子“ Transactions”,用于存储过去的事务。因此,获取整个数据库将获取不需要的数据(增加超时)。
def post_menu(request):
vendors = database.child('Vendors').shallow().get().val()
curr_vendor_list = [i for i in vendors if database.child('Vendors').child(i).child('email').get().val() == request.user.email]
if curr_vendor_list:
curr_vendor = curr_vendor_list[0]
else:
error_msg = {'msg': "You are not a registered Vendor!"}
return render(request, 'Authentication/login.html', error_msg)
if request.method == 'POST':
category = request.POST.get('category')
if category == 'new':
category_name = request.POST.get('category_input')
elif category == 'existing':
category_name = request.POST.get('category_select')
else:
return redirect('Vendor:reviews')
item_name = request.POST.get('item')
ingredients = request.POST.get('ingredients')
mark = request.POST.get('mark')
price = request.POST.get('price')
dict_item_properties = {'ingredients': ingredients, 'mark': mark, 'price': price}
if category == 'new':
dict_item = {item_name: dict_item_properties}
database.child('Menus').child(curr_vendor).child(category_name).set(dict_item)
elif category == 'existing':
database.child('Menus').child(curr_vendor).child(category_name).child(item_name).set(dict_item_properties)
return redirect('Vendor:menu')
return redirect('Vendor:reviews')