I use Go with github.com/go-sql-driver/mysql to connect to MySQL. The 
performance in Go vs other languages is terrible or I'm missing something.

I use Go for my REST API, an example is below:

We have a table with posts. We fetch the posts, on each post we search 
favorites table (if user has favorited this post and if he likes it).

posts := make([]*MembersModel.Post, 0, 6)

postsResults, err := Config.DB.Query("SELECT id, b64, title, description, 
total_likes,  total_favorites, published_date  FROM posts ORDER BY id DESC 
LIMIT 6")

    defer postsResults.Close()

    if err != nil {
        fmt.Println(err)
        panic(err.Error()) 
    }

    for postsResults.Next() {
        var postID int
        var b64 string
        var title string
        var description string
        var total_likes int
        var total_favorites int
        var published_date string

        postsResults.Scan(&id, &b64, &title, &description, &total_likes, 
&total_favorites, &published_date)

        var count int
        var favorited string

        fetchBookmarks := Config.DB.QueryRow("SELECT COUNT(*) FROM favorites 
where userID = ? and postID = ? and status = ?", userID, postID, 
"added").Scan(&count)

        if fetchBookmarks != nil {
            fmt.Println("error")
        }

        if count == 0 {
            favorited = "no"
        } else {
            favorited = "yes"
        }

        var countSubmitted int
        var likedPost string

        fetchLikes := Config.DB.QueryRow("SELECT COUNT(*) FROM likes where 
userID = ? and postID = ? and status=?", userID, postID, 
"liked").Scan(&countSubmitted)

        if fetchLikes != nil {
            fmt.Println("error")
        }

        if countSubmitted == 0 {
            likedPost = "no"
        } else {
            likedPost = "yes"
        }

        post := &MembersModel.JobList{
            PostID:        b64,
            Title: title,
            Description:     description,
            Likes:   total_likes,
            PubDate:   published_date,
            Bookmarked:   favorited,
            Liked:     likedPost,
        }

        posts = append(posts, post)
    }

Average time to fetch these results -> 10 seconds!

If I exclude the MYSQL calls inside the loop, the time to fetch these results 
is 300ms.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/e3f758d8-595f-4f0d-9aa6-d0b87899007fo%40googlegroups.com.

Reply via email to