2023-08-05 14:32:56 (UTC-03:00)
Marcel Rodrigues <marcelgmr@gmail.com>
use join instead of ancillary table
diff --git a/data.lua b/data.lua index 77a8faa..66fb8cf 100644 --- a/data.lua +++ b/data.lua @@ -195,8 +195,17 @@ function Model:create_ticket(user_id, proj_id, title, desc, priority) return code end -function Model:get_ticket(proj_id, code) - local query = "SELECT * FROM Ticket WHERE proj_id = ? AND code = ?;" +function Model:get_ticket(proj_id, code, full) + local query + if full then + query = [[ + SELECT Ticket.*, User.nick AS author_nick, User.name AS author_name + FROM Ticket JOIN User ON Ticket.user_id = User.id + WHERE Ticket.proj_id = ? AND Ticket.code = ?; + ]] + else + query = "SELECT * FROM Ticket WHERE proj_id = ? AND code = ?;" + end return self.db:execute(query, proj_id, code)[1] end diff --git a/skopos.lua b/skopos.lua index 343f33f..9764bfc 100644 --- a/skopos.lua +++ b/skopos.lua @@ -219,14 +219,13 @@ function App:routes() if user == nil then return "/login", 303 end local proj = self.model:get_user_project(user.id, name) if proj == nil then return "not found", 404 end - local tick = self.model:get_ticket(proj.id, tonumber(code)) + local tick = self.model:get_ticket(proj.id, code, true) if tick == nil then return "not found", 404 end - local users = self.model:get_indexed_users() -- TODO: load comments local comments = {} local env = { title=self.title, user=user, proj=proj, tick=tick, - users=users, states=self.model.states, comments=comments + states=self.model.states, comments=comments } return lud.template.render_file("view/ticket.html", env) end}, diff --git a/view/ticket.html b/view/ticket.html index d35d57b..05006bd 100644 --- a/view/ticket.html +++ b/view/ticket.html @@ -10,15 +10,14 @@ </style> </head> <body> - <h1 class="centered">{{$proj.name}} - Ticket #{{$tick.code}}</h1> + <h1 class="centered">{{$proj.name}} - ticket #{{$tick.code}}</h1> <div class="ticket-details"> <h1>{{$tick.title}}</h1> <div class="header-details"> <p class="date"><strong>Date:</strong> {{os.date("%Y-%m-%d", $tick.time)}}</p> - % set author = $users[$tick.user_id] <p class="author"> <strong>Author:</strong> - <a href="/u/{{$author.nick}}">{{$author.name}}</a> + <a href="/u/{{$tick.author_nick}}">{{$tick.author_name}}</a> </p> </div> <pre>{{$tick.desc}}</pre> @@ -39,10 +38,9 @@ <div class="comment"> <div class="header-details"> <p class="date"><strong>Date:</strong> {{os.date("%Y-%m-%d", $comment.time)}}</p> - % set author = $users[$comment.user_id] <p class="author"> <strong>Author:</strong> - <a href="/u/{{$author.nick}}">{{$author.name}}</a> + <a href="/u/{{$comment.author_nick}}">{{$comment.author_name}}</a> </p> </div> <pre>{{$comment.text}}</pre>