Template and prepared statement caching

This commit is contained in:
2025-08-16 17:28:38 +02:00
parent 67d1eb2304
commit 7baba9657d
15 changed files with 963 additions and 433 deletions
+10 -3
View File
@@ -1,6 +1,6 @@
include "pages/page.wl"
let posts = $query("SELECT id, title, is_link, content, 0 as num_comments, CURRENT_TIMESTAMP as date FROM Posts")
let posts = $query("SELECT P.id, P.title, P.is_link, P.content, (SELECT COUNT(*) FROM Comments as C WHERE c.parent_post=P.id) as num_comments, CURRENT_TIMESTAMP as date FROM Posts as P")
if posts == none:
posts = []
@@ -30,13 +30,20 @@ let style =
width: 250px;
text-align: right;
}
#no-posts {
margin: 60px auto;
width: 100%;
text-align: center;
color: #7A5F2A;
}
</style>
let main =
<main>
\if len(posts) == 0:
<div>There are no posts yet!</div>
<div id="no-posts">There are no posts yet!</div>
\for post in posts: {
@@ -51,7 +58,7 @@ let main =
<a href=\'"'\link\'"'>\post.title</a>
</div>
<div>
<span>\post.date</span> | <span><a href=\'"'\link\'"'>\post.num_comments comments</a></span>
<span>\post.date</span> | <span>\post.num_comments comments</span>
</div>
</div>
}
+4 -1
View File
@@ -4,7 +4,10 @@ include "pages/login_and_signup_style.wl"
let main =
<main>
<span>Welcome back!</span>
<form action="/api/login" method="POST">
<div id="response"></div>
<form hx-post="/api/login" hx-target="#response">
<input type="text" name="username" placeholder="username" />
<input type="password" name="password" placeholder="password" />
<input type="submit" value="Log-In" />
+12
View File
@@ -59,4 +59,16 @@ let style =
.form-links a:hover {
color: #1D2B42;
}
#response {
max-width: 300px;
margin: auto;
}
#response .error {
margin-top: 30px;
border-radius: 3px;
border: 1px solid #E44C82;
background: #F295B5;
padding: 5px 10px;
}
</style>
+5 -4
View File
@@ -43,15 +43,16 @@ procedure page(title, login_user_id, style, main)
}
</style>
\(style)
<script src="https://cdnjs.cloudflare.com/ajax/libs/htmx/1.9.2/htmx.min.js"></script>
</head>
<body>
<nav>
<div>
<a href="/index">index</a>
\if login_user_id != none: {
"|\n"
<a href="/write">write</a>
}
\if login_user_id != none: {
"|\n"
<a href="/write">write</a>
}
</div>
\if login_user_id == none:
<div>
+20 -16
View File
@@ -118,21 +118,17 @@ let style =
margin-left: 10px;
}
.add-comment {
margin: 20px 0;
padding: 15px;
background: #E8D4A9;
border-radius: 3px;
border: 1px solid #D4C298;
}
.add-comment form {
margin: 0;
overflow: auto;
}
.add-comment form textarea {
width: 100%;
height: 80px;
font-family: monospace;
font-size: 12px;
background: #F7E6C0;
background: white;
border: 1px solid #D4C298;
border-radius: 3px;
padding: 8px;
@@ -141,7 +137,7 @@ let style =
}
.add-comment form input[type=submit] {
background: #5780C9;
color: #F7E6C0;
color: white;
border: none;
border-radius: 3px;
padding: 6px 12px;
@@ -149,6 +145,7 @@ let style =
font-size: 12px;
cursor: pointer;
margin-top: 8px;
float: right;
}
.add-comment input[type=submit]:hover {
background: #1D2B42;
@@ -162,14 +159,19 @@ let style =
::-webkit-details-marker {
display: none;
}
.collapsed {
#no-comments {
margin: 30px 0;
width: 100%;
text-align: center;
color: #7A5F2A;
font-size: 11px;
cursor: pointer;
}
.collapsed:hover {
color: #1D2B42;
pre {
white-space: pre-wrap; /* Since CSS 2.1 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
</style>
@@ -183,7 +185,7 @@ let main =
submitted 3 hours ago by <a href="">\post.username</a> | <a href="">\len comments</a>
</div>
<div class="thread-text">
\post.content
<pre>\post.content</pre>
</div>
<details>
<summary>
@@ -210,7 +212,7 @@ let main =
<a href="">\comment.username</a> 2 hours ago
</div>
<div class="comment-text">
\comment.content
<pre>\comment.content</pre>
</div>
\if $login_user_id != none:
<details>
@@ -234,7 +236,9 @@ let main =
</div>
\if len root_comments == 0:
<span>(No comments)</span>
<div id="no-comments">
No comments
</div>
else for comment in root_comments:
render_comment(comment)
</main>
+4 -1
View File
@@ -4,7 +4,10 @@ include "pages/login_and_signup_style.wl"
let main =
<main>
<span>Welcome!</span>
<form action="/api/signup" method="POST">
<div id="response"></div>
<form hx-post="/api/signup" hx-target="#response">
<input type="text" name="username" placeholder="username" />
<input type="email" name="email" placeholder="email" />
<input type="password" name="password1" placeholder="password" />