Permalink
Browse files

Optimize getEvent

  • Loading branch information...
methane committed Sep 16, 2018
1 parent 6fe4431 commit 0bf2bd3a120b479dc2ca3b64b26c71e0da549c42
Showing with 17 additions and 11 deletions.
  1. +15 −9 webapp/go/src/torb/app.go
  2. +2 −2 webapp/go/src/torb/reservation.go
View
@@ -261,6 +261,10 @@ func getEvent(eventID, loginUserID int64) (*Event, error) {
//reservations := getReservationForEvent(eventID)
// ここを効率化
reservations, reservedSheets := getReservationForEvent(eventID)
if len(reservedSheets) == 0 {
reservedSheets = make([]int64, 1001)
}
var sheetID int64
for sheetID = 1; sheetID <= 1000; sheetID++ {
@@ -269,17 +273,19 @@ func getEvent(eventID, loginUserID int64) (*Event, error) {
event.Total++
event.Sheets[sheet.Rank].Total++
var reservation Reservation
err := db.QueryRow("SELECT * FROM reservations WHERE event_id = ? AND sheet_id = ? AND canceled_at IS NULL GROUP BY event_id, sheet_id HAVING reserved_at = MIN(reserved_at)", event.ID, sheet.ID).Scan(&reservation.ID, &reservation.EventID, &reservation.SheetID, &reservation.UserID, &reservation.ReservedAt, &reservation.CanceledAt)
if err == nil {
sheet.Mine = reservation.UserID == loginUserID
if reservedSheets[sheetID] != 0 {
sheet.Mine = reservedSheets[sheetID] == loginUserID
sheet.Reserved = true
sheet.ReservedAtUnix = reservation.ReservedAt.Unix()
} else if err == sql.ErrNoRows {
for _, r := range reservations {
if r.SheetID == sheetID {
sheet.ReservedAtUnix = r.ReservedAt.Unix()
break
}
}
//sheet.ReservedAtUnix = reservation.ReservedAt.Unix()
} else {
event.Remains++
event.Sheets[sheet.Rank].Remains++
} else {
return nil, err
}
event.Sheets[sheet.Rank].Detail = append(event.Sheets[sheet.Rank].Detail, &sheet)
@@ -934,7 +940,7 @@ func main() {
return renderReportCSV(c, reports)
}, adminLoginRequired)
e.Start(":8080")
log.Print(e.Start(":8080"))
}
type Report struct {
@@ -54,10 +54,10 @@ func initReservation() {
}
}
func getReservationForEvent(eventID int64) []Reservation {
func getReservationForEvent(eventID int64) ([]Reservation, []int64) {
mReservation.Lock()
defer mReservation.Unlock()
return eventReservations[eventID]
return eventReservations[eventID], eventReservedFlags[eventID]
}
func doReserve(eventID, userID int64, rank string) (int64, int64, error) {

0 comments on commit 0bf2bd3

Please sign in to comment.