ComputerScienceHouse / audiophiler

s3 audio file storage flask app with templated front end

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

places that need to be optimized

sgreene570 opened this issue · comments

@sgreene570 those links are leading to bendigo. What are the new line numbers if they still need to be optimised?

I believe the entirety of the second link's function body could be replaced with:

return Harold.query.filter_by(owner=uid).all()

do it up

Prototyping my change for L211:

# This is a post route since auth_key is required
@app.route("/get_harold/<string:uid>", methods=["POST"])
def get_harold(uid, auth_dict=None):
    data_dict = request.get_json()
    if data_dict["auth_key"]:
        auth_model = Auth.query.filter_by(auth_key=data_dict["auth_key"]).first()
        if auth_model:
            harold_file_hash = None
            harolds_list = get_harold_list(uid)
            if len(harolds_list) == 0:
                harold_file_hash = get_random_harold()
            else:
                harold_file_hash = random.choice(harolds_list)

            return get_file_s3(s3_bucket, harold_file_hash)

    return "Permission denied", 403

And for L116:

# Check if file hash is the same as any files already in the db
if File.query.filter_by(file_hash=file_hash).first():
    upload_status["error"].append(filename)
    break

Regarding database optimisations that can be done to speed up the queries, @sgreene570 double check that you have indexes on:

  • The author column in the File table
  • The file_hash column in the File table
  • The file_hash column in the Harold table
  • The owner column in the Harold table

Nice. Basically any case where you're filtering by a column, there should be an index on that column.