mirror of
https://github.com/rystaf/mlmym.git
synced 2024-11-25 06:25:46 +00:00
remove redundant child counts, only insert new
This commit is contained in:
parent
2b0eefa172
commit
37e62d2e5f
|
@ -115,8 +115,8 @@ summary {
|
||||||
.title a p {
|
.title a p {
|
||||||
display: inline;
|
display: inline;
|
||||||
}
|
}
|
||||||
.post.distinguished .title a,
|
.post.distinguished .title a, .post.announcement .title a,
|
||||||
.dark .post.distinguished .title a:visited {
|
.dark .post.distinguished .title a:visited, .post.announcement .title a:visited {
|
||||||
color: #228822;
|
color: #228822;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
@ -228,6 +228,13 @@ summary {
|
||||||
.dark .meta a {
|
.dark .meta a {
|
||||||
color: #6a98af;
|
color: #6a98af;
|
||||||
}
|
}
|
||||||
|
.comment .meta a.distinguished.admin, .post.distinguished a.admin, .post.announcement a.admin {
|
||||||
|
background-color: #ff0011;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
border-radius: 3px;
|
||||||
|
padding: 0px 2px;
|
||||||
|
}
|
||||||
.meta a:hover {
|
.meta a:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
@ -472,7 +479,7 @@ form.nsfw div {
|
||||||
.expando-button:hover{
|
.expando-button:hover{
|
||||||
background-color: #466599;
|
background-color: #466599;
|
||||||
}
|
}
|
||||||
.expando-button.hidden, .children.hidden .comment {
|
.expando-button.hidden, .children.hidden .comment, .children.hidden .morecomments {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.hidechildren .show {
|
.hidechildren .show {
|
||||||
|
|
|
@ -91,8 +91,7 @@ function commentClick(e) {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ((e.target.className.indexOf("loadmore") != -1) ||
|
if ((e.target.className.indexOf("edit") != -1) ||
|
||||||
(e.target.className.indexOf("edit") != -1) ||
|
|
||||||
(e.target.className.indexOf("source") != -1) ||
|
(e.target.className.indexOf("source") != -1) ||
|
||||||
(e.target.className.indexOf("reply") != -1)) {
|
(e.target.className.indexOf("reply") != -1)) {
|
||||||
var id = targ.id
|
var id = targ.id
|
||||||
|
@ -104,6 +103,32 @@ function commentClick(e) {
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
if (e.target.className.indexOf("loadmore") != -1) {
|
||||||
|
var id = targ.id
|
||||||
|
if (e.target.getAttribute("for") != id) { return }
|
||||||
|
e.preventDefault()
|
||||||
|
var comments = targ.getElementsByClassName("comment")
|
||||||
|
var skip = []
|
||||||
|
for (var i = 0; i < comments.length; i++) {
|
||||||
|
skip.push(comments[i].id)
|
||||||
|
}
|
||||||
|
request(e.target.href+"&xhr",false, function(res){
|
||||||
|
var parent = e.target.parentNode
|
||||||
|
parent.innerHTML = res
|
||||||
|
parent.innerHTML = parent.getElementsByClassName("children")[0].innerHTML
|
||||||
|
var comments = parent.getElementsByClassName("comment")
|
||||||
|
for (var i = 0; i < skip.length; i++) {
|
||||||
|
for (var c = 0; c < comments.length; c++) {
|
||||||
|
if (skip[i] == comments[c].id) {
|
||||||
|
comments[c].remove()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parent.outerHTML = parent.innerHTML
|
||||||
|
setup()
|
||||||
|
})
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadMoreComments(e) {
|
function loadMoreComments(e) {
|
||||||
|
|
|
@ -165,6 +165,9 @@ var funcMap = template.FuncMap{
|
||||||
"sub": func(a int32, b int) int {
|
"sub": func(a int32, b int) int {
|
||||||
return int(a) - b
|
return int(a) - b
|
||||||
},
|
},
|
||||||
|
"add": func(a int32, b int) int {
|
||||||
|
return int(a) + b
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func Initialize(Host string, r *http.Request) (State, error) {
|
func Initialize(Host string, r *http.Request) (State, error) {
|
||||||
|
|
7
state.go
7
state.go
|
@ -627,19 +627,19 @@ func (state *State) UploadImage(file multipart.File, header *multipart.FileHeade
|
||||||
|
|
||||||
func getChildren(parent *Comment, pool []types.CommentView, postCreatorID int) {
|
func getChildren(parent *Comment, pool []types.CommentView, postCreatorID int) {
|
||||||
var children []Comment
|
var children []Comment
|
||||||
total := -1
|
total := int32(0)
|
||||||
for _, c := range pool {
|
for _, c := range pool {
|
||||||
levels := strings.Split(c.Comment.Path, ".")
|
levels := strings.Split(c.Comment.Path, ".")
|
||||||
for i, l := range levels {
|
for i, l := range levels {
|
||||||
id, _ := strconv.Atoi(l)
|
id, _ := strconv.Atoi(l)
|
||||||
if id == parent.P.Comment.ID {
|
if id == parent.P.Comment.ID {
|
||||||
total = total + 1
|
|
||||||
if i == (len(levels) - 2) {
|
if i == (len(levels) - 2) {
|
||||||
children = append(children, Comment{
|
children = append(children, Comment{
|
||||||
P: c,
|
P: c,
|
||||||
C: children,
|
C: children,
|
||||||
State: parent.State,
|
State: parent.State,
|
||||||
})
|
})
|
||||||
|
total += c.Counts.ChildCount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -647,7 +647,8 @@ func getChildren(parent *Comment, pool []types.CommentView, postCreatorID int) {
|
||||||
}
|
}
|
||||||
for i, _ := range children {
|
for i, _ := range children {
|
||||||
getChildren(&children[i], pool, postCreatorID)
|
getChildren(&children[i], pool, postCreatorID)
|
||||||
|
parent.ChildCount += 1
|
||||||
}
|
}
|
||||||
parent.C = children
|
parent.C = children
|
||||||
parent.ChildCount = total
|
parent.P.Counts.ChildCount -= total
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
[-]
|
[-]
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</a>
|
</a>
|
||||||
<a {{ if .P.Comment.Distinguished}}class="distinguished"{{ else if .Submitter }}class="submitter"{{end}} href="/{{.State.Host}}/u/{{fullname .P.Creator}}">{{fullname .P.Creator}}</a>
|
<a {{ if .P.Comment.Distinguished}}class="{{if .P.Creator.Admin}}admin {{end}}distinguished"{{ else if .Submitter }}class="submitter"{{end}} href="/{{.State.Host}}/u/{{fullname .P.Creator}}">{{fullname .P.Creator}}</a>
|
||||||
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span>
|
<b>{{.P.Counts.Score}} points</b> <span title="{{.P.Comment.Published.Time}}">{{ humanize .P.Comment.Published.Time }}</span>
|
||||||
{{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}}
|
{{- if gt .P.Comment.Updated.Time.Unix .P.Comment.Published.Time.Unix -}}
|
||||||
* (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>)
|
* (last edited <span title="{{.P.Comment.Updated.Time}}">{{ humanize .P.Comment.Updated.Time }}</span>)
|
||||||
|
@ -97,8 +97,8 @@
|
||||||
<a href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?context=3">context</a>
|
<a href="/{{.State.Host}}/comment/{{.P.Comment.ID}}?context=3">context</a>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if gt .ChildCount 0 }}
|
{{ if and .State.PostID (gt (add .P.Counts.ChildCount .ChildCount) 0) }}
|
||||||
<li><a class="hidechildren" for="c{{.P.Comment.ID}}" href=""><span class="hide">hide</span><span class="show">show {{ .ChildCount }}</span> child comments</a></li>
|
<li><a class="hidechildren" for="c{{.P.Comment.ID}}" href=""><span class="hide">hide</span><span class="show">show {{add .P.Counts.ChildCount .ChildCount }}</span> child comments</a></li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<head>
|
<head>
|
||||||
<title>{{ if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}</title>
|
<title>{{ if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}</title>
|
||||||
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
|
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
|
||||||
<link rel="stylesheet" href="/_/static/style.css?v=21">
|
<link rel="stylesheet" href="/_/static/style.css?v=23">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
</head>
|
</head>
|
||||||
<body {{ if .Dark }}class="dark"{{end}}>
|
<body {{ if .Dark }}class="dark"{{end}}>
|
||||||
|
@ -56,6 +56,6 @@
|
||||||
{{ template "sidebar.html" . }}
|
{{ template "sidebar.html" . }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<script src="/_/static/utils.js?v=17"></script>
|
<script src="/_/static/utils.js?v=19"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<title>{{if and .Posts .PostID }}{{ (index .Posts 0).Post.Name}} : {{.CommunityName}}{{else if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}</title>
|
<title>{{if and .Posts .PostID }}{{ (index .Posts 0).Post.Name}} : {{.CommunityName}}{{else if and .Community (ne .Community.CommunityView.Community.Title "")}}{{.Community.CommunityView.Community.Title}}{{else if ne .CommunityName ""}}/c/{{.CommunityName}}{{ else if .User}}overview for {{.User.PersonView.Person.Name}}{{else}}{{ host .Host }}{{end}}</title>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
|
<link rel="shortcut icon" href="/{{.Host}}/icon.jpg">
|
||||||
<link rel="stylesheet" href="/_/static/style.css?v=21">
|
<link rel="stylesheet" href="/_/static/style.css?v=23">
|
||||||
</head>
|
</head>
|
||||||
<body{{ if .Dark }} class="dark"{{end}}>
|
<body{{ if .Dark }} class="dark"{{end}}>
|
||||||
<noscript>
|
<noscript>
|
||||||
|
@ -133,7 +133,7 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
<script src="/_/static/utils.js?v=17"></script>
|
<script src="/_/static/utils.js?v=19"></script>
|
||||||
{{ template "sidebar.html" . }}
|
{{ template "sidebar.html" . }}
|
||||||
</main>
|
</main>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{{ if and (ne .State.Op "vote_post") (ne .State.Op "save_post") }}
|
{{ if and (ne .State.Op "vote_post") (ne .State.Op "save_post") }}
|
||||||
<div class="post{{if .Post.Deleted}} deleted{{end}}{{ if or .Post.FeaturedCommunity .Post.FeaturedLocal }} distinguished{{end}}">
|
<div class="post{{if .Post.Deleted}} deleted{{end}}{{ if .Post.FeaturedCommunity }} distinguished{{end}}{{if .Post.FeaturedLocal }} announcement{{end}}">
|
||||||
{{ if gt .Rank 0 }}
|
{{ if gt .Rank 0 }}
|
||||||
<div class="rank"> {{ .Rank }} </div>
|
<div class="rank"> {{ .Rank }} </div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
* (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>)
|
* (last edited <span title="{{.Post.Updated.Time}}">{{ humanize .Post.Updated.Time }}</span>)
|
||||||
{{ end }}
|
{{ end }}
|
||||||
by
|
by
|
||||||
<a href="/{{ .State.Host }}/u/{{ fullname .Creator }}">{{ fullname .Creator }}</a>
|
<a class="submitter{{ if .Creator.Admin}} admin{{end}}" href="/{{ .State.Host }}/u/{{ fullname .Creator }}">{{ fullname .Creator }}</a>
|
||||||
to
|
to
|
||||||
<a href="/{{ .State.Host }}/c/{{ fullcname .Community }}">c/{{ fullcname .Community}}</a>
|
<a href="/{{ .State.Host }}/c/{{ fullcname .Community }}">c/{{ fullcname .Community}}</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue