Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
See what's new at GitLab
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
C
colt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nala Ginrut
colt
Commits
14115fec
Verified
Commit
14115fec
authored
Mar 23, 2020
by
Nala Ginrut
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize post/edit/remove speed
parent
364f2c26
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
75 additions
and
35 deletions
+75
-35
app/controllers/dashboard.scm
app/controllers/dashboard.scm
+3
-3
app/models/posts.scm
app/models/posts.scm
+62
-27
app/views/dashboard/login.html.tpl
app/views/dashboard/login.html.tpl
+1
-1
lib/colt/git.scm
lib/colt/git.scm
+9
-4
No files found.
app/controllers/dashboard.scm
View file @
14115fec
...
...
@@ -114,7 +114,7 @@
(
"comment_status"
.
"closed"
)))
(
oid
(
git-post-article
url-name
article-content
article-meta
)))
(
update-index-posts-cache
)
(
update-index-posts-cache
oid
'post
)
oid
)))
(
post
"/v1/colt/edit_article"
...
...
@@ -133,7 +133,7 @@
(
oid
(
git-edit-article
article-title
article-name
article-content
article-oid
article-tags
article-status
update-timestamp?
)))
(
update-index-posts-cache
)
(
update-index-posts-cache
oid
'edit
)
oid
)))
(
post
"/v1/colt/remove_article"
...
...
@@ -147,7 +147,7 @@
(
article-oid
(
hash-ref
json-content
"oid"
))
(
status
(
git-remove-article
article-title
article-content
article-oid
)))
(
update-index-posts-cache
)
(
update-index-posts-cache
article-oid
'remove
)
(
if
(
string=?
status
"failed"
)
"failed"
"ok"
))))
...
...
app/models/posts.scm
View file @
14115fec
;; -*- indent-tabs-mode:nil; coding: utf-8 -*-
;; Copyright (C) 2017,2019
;; Copyright (C) 2017,2019
,2020
;; "Mu Lei" known as "NalaGinrut" <NalaGinrut@gmail.com>
;; Colt is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License
...
...
@@ -64,41 +64,43 @@
(
define
*intro*
'
())
(
define
*all-tags*
(
make-hash-table
))
(
define
(
refresh-tags
)
(
for-each
(
lambda
(
p
)
(
for-each
(
lambda
(
t
)
(
let
((
pl
(
hash-ref
*all-tags*
t
'
())))
(
hash-set!
*all-tags*
t
(
cons
p
pl
))))
(
tags-string->list
(
post-tags
p
))))
*all-post-objs*
))
(
define
(
sort-by-time
objs
)
(
sort
objs
(
lambda
(
x
y
)
(
>=
(
string->number
(
post-timestamp
x
))
(
string->number
(
post-timestamp
y
))))))
(
define*
(
get-all-post-objs
#
:key
(
latest-top?
#t
)
(
refresh?
#f
))
(
define
(
sort-by-time
objs
)
(
sort
objs
(
lambda
(
x
y
)
(
>=
(
string->number
(
post-timestamp
(
get-post
x
)))
(
string->number
(
post-timestamp
(
get-post
y
)))))))
(
define
return
(
if
latest-top?
identity
reverse
))
(
define
(
filter-me
obj
s
)
(
partition
(
lambda
(
o
)
(
string=?
"_____colt_____Intro"
(
post-title
(
get-post
o
)
)))
obj
s
))
(
define
(
filter-me
post
s
)
(
partition
(
lambda
(
p
)
(
string=?
"_____colt_____Intro"
(
post-title
p
)))
post
s
))
(
when
refresh?
(
set!
*all-post-objs*
'
()))
(
cond
((
not
(
null?
*all-post-objs*
))
(
return
*all-post-objs*
))
(
else
(
let
((
obj
s
(
sort-by-time
(
git/get-post-objs
))))
(
let
((
post
s
(
sort-by-time
(
git/get-post-objs
))))
(
call-with-values
(
lambda
()
(
filter-me
obj
s
))
(
lambda
()
(
filter-me
post
s
))
(
lambda
(
intro
all
)
(
set!
*all-post-objs*
all
)
(
set!
*intro*
(
map
get-post
intro
))
;; init tags
(
for-each
(
lambda
(
o
)
(
for-each
(
lambda
(
t
)
(
let
((
pl
(
hash-ref
*all-tags*
t
'
())))
(
hash-set!
*all-tags*
t
(
cons
(
get-post
o
)
pl
))))
(
tags-string->list
(
post-tags
(
get-post
o
)))))
all
)))
(
set!
*intro*
intro
)
(
refresh-tags
)))
(
return
*all-post-objs*
)))))
(
define*
(
get-all-posts
#
:key
(
latest-top?
#t
)
(
refresh?
#f
))
(
map
get-post
(
get-all-post-objs
#
:latest-top?
latest-top?
#
:refresh?
refresh?
)
))
(
get-all-post-objs
#
:latest-top?
latest-top?
#
:refresh?
refresh?
))
(
define
(
get-posts-by-tag
tag
)
(
hash-ref
*all-tags*
(
uri-decode
tag
)
'
()))
...
...
@@ -128,10 +130,43 @@
(
define
(
get-the-latest-post-update-time
)
(
post-timestamp
(
get-the-latest-post
)))
(
define
(
update-index-posts-cache
)
(
define
(
get-one-post-from-git
oid
)
(
let
((
ol
(
git-ls-tree
)))
(
get-post-by-oid
oid
ol
)))
(
define
(
cache-the-post!
oid
op
)
(
let
((
new-post
(
get-one-post-from-git
oid
)))
(
cond
((
eq?
op
'post
)
(
set!
*all-post-objs*
(
sort-by-time
(
cons
new-post
*all-post-objs*
))))
((
eq?
op
'edit
)
(
let
((
url-name
(
uri-decode
(
post-url-name
new-post
))))
(
set!
*all-post-objs*
(
sort-by-time
(
cons
new-post
(
filter
(
lambda
(
p
)
(
not
(
string=?
url-name
(
uri-decode
(
post-url-name
p
)))))
*all-post-objs*
)))))
(
refresh-tags
))
((
eq?
op
'remove
)
(
set!
*all-post-objs*
(
filter
(
lambda
(
p
)
(
not
(
string=?
oid
(
post-oid
p
))))
*all-post-objs*
))
(
refresh-tags
))
(
else
(
throw
'artanis-err
500
cache-the-post!
"Invalid operation or oid: ~a, ~a"
op
oid
)))))
(
define*
(
update-index-posts-cache
#
:optional
(
oid
#f
)
(
op
'post
))
(
clear-content-cache
"index"
)
(
clear-content-cache
"atom/feed"
)
(
get-all-posts
#
:refresh?
#t
))
(
clear-content-cache
"feed/atom"
)
(
if
oid
(
cache-the-post!
oid
op
)
(
get-all-posts
#
:refresh?
#t
)))
(
define
(
get-posts-from-n-to-m
n
m
posts-list
)
(
if
(
null?
posts-list
)
...
...
@@ -260,7 +295,7 @@
(
generate-pages-content
mode
(
get-intro-page
)))
(
define
(
get-one-article-by-oid
oid
)
(
let
((
post
(
get-post-by-oid
oid
(
get-all-post-objs
))))
(
let
((
post
(
get-post-
in-pl-
by-oid
oid
(
get-all-post-objs
))))
(
when
(
not
post
)
(
throw
'artanis-err
404
get-one-article-by-oid
"Invalid oid (~a)!"
oid
))
...
...
app/views/dashboard/login.html.tpl
View file @
14115fec
...
...
@@ -12,7 +12,7 @@
<
@
css
materialize.min.css
%
>
<
@
css
blog.css
%
>
<
@
css
custom-blue-theme.css
%
>
<
@
js
jquery-3.
3
.1.min.js
%
>
<
@
js
jquery-3.
4
.1.min.js
%
>
<
@
js
materialize.min.js
%
>
<script>
$
(
"
#reset
"
).
on
(
"
click
"
,
function
()
{
...
...
lib/colt/git.scm
View file @
14115fec
...
...
@@ -33,7 +33,9 @@
get-object-by-oid
get-object-by-name
get-post-by-oid
get-post-in-pl-by-oid
get-post
git-object-oid
post-meta-data
post-content
...
...
@@ -157,6 +159,9 @@
(
define
(
get-post-by-oid
oid
obj-list
)
(
any
(
lambda
(
o
)
(
and
(
string=?
oid
(
git-object-oid
o
))
(
get-post
o
)))
obj-list
))
(
define
(
get-post-in-pl-by-oid
oid
post-list
)
(
any
(
lambda
(
p
)
(
and
(
string=?
oid
(
post-oid
p
))
p
))
post-list
))
(
define*
(
git-ls-tree
#
:key
(
branch
"master"
))
(
cmd-result-map
(
lambda
(
o
)
...
...
@@ -350,12 +355,12 @@
(
make-post
meta-data
content
comments
url-name
oid
)))
(
define
(
git/get-post-objs
)
(
let
((
ol
(
git-ls-tree
)))
(
let
((
pl
(
map
get-post
(
git-ls-tree
)
)))
(
filter
(
lambda
(
o
)
(
not
(
string=?
(
meta-data-status
(
post-meta-data
(
get-post
o
)
))
(
lambda
(
p
)
(
not
(
string=?
(
meta-data-status
(
post-meta-data
p
))
"deleted"
)))
o
l
)))
p
l
)))
(
define
(
git-db-init
)
(
cmd
git
init
--bare
--quiet
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment