aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Magorsch <arzano@gentoo.org>2020-06-22 00:45:14 +0000
committerMax Magorsch <arzano@gentoo.org>2020-06-22 00:45:14 +0000
commit2149bb7fb6b6f732ac8364e45d072a22921957db (patch)
treeb72b5b876489df7cbec280b06440b89f9fe46a2d /pkg/app/list
parentImprove the error handling during the import (diff)
downloadarchives-2149bb7fb6b6f732ac8364e45d072a22921957db.tar.gz
archives-2149bb7fb6b6f732ac8364e45d072a22921957db.tar.bz2
archives-2149bb7fb6b6f732ac8364e45d072a22921957db.zip
Rework the data model to improve the performance
Signed-off-by: Max Magorsch <arzano@gentoo.org>
Diffstat (limited to 'pkg/app/list')
-rw-r--r--pkg/app/list/messages.go20
-rw-r--r--pkg/app/list/show.go18
-rw-r--r--pkg/app/list/threads.go23
3 files changed, 30 insertions, 31 deletions
diff --git a/pkg/app/list/messages.go b/pkg/app/list/messages.go
index 383e891..7a78811 100644
--- a/pkg/app/list/messages.go
+++ b/pkg/app/list/messages.go
@@ -33,20 +33,20 @@ func Messages(w http.ResponseWriter, r *http.Request) {
var messages []*models.Message
query := database.DBCon.Model(&messages).
- Column("id", "headers", "date").
+ Column("id", "subject", "from", "date").
Where("to_char(date, 'YYYY-MM') = ?", combinedDate).
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
- q = q.WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE '[` + listName + `]%'`).
- WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE 'Re: [` + listName + `]%'`)
- return q, nil
- }).
- WhereGroup(func(q *orm.Query) (*orm.Query, error) {
- q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@lists.gentoo.org%'`).
- WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@lists.gentoo.org%'`).
- WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@gentoo.org%'`).
- WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@gentoo.org%'`)
+ q = q.WhereOr(`subject LIKE '[` + listName + `]%'`).
+ WhereOr(`subject LIKE 'Re: [` + listName + `]%'`)
return q, nil
}).
+ //WhereGroup(func(q *orm.Query) (*orm.Query, error) {
+ // q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@lists.gentoo.org%'`).
+ // WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@lists.gentoo.org%'`).
+ // WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@gentoo.org%'`).
+ // WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@gentoo.org%'`)
+ // return q, nil
+ //}).
Order("date DESC")
messagesCount, _ := query.Count()
diff --git a/pkg/app/list/show.go b/pkg/app/list/show.go
index 8db8778..d90f236 100644
--- a/pkg/app/list/show.go
+++ b/pkg/app/list/show.go
@@ -18,17 +18,17 @@ func Show(w http.ResponseWriter, r *http.Request) {
}
err := database.DBCon.Model((*models.Message)(nil)).
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
- q = q.WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE '[` + listName + `]%'`).
- WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE 'Re: [` + listName + `]%'`)
- return q, nil
- }).
- WhereGroup(func(q *orm.Query) (*orm.Query, error) {
- q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@lists.gentoo.org%'`).
- WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@lists.gentoo.org%'`).
- WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@gentoo.org%'`).
- WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@gentoo.org%'`)
+ q = q.WhereOr(`subject LIKE '[` + listName + `]%'`).
+ WhereOr(`subject LIKE 'Re: [` + listName + `]%'`)
return q, nil
}).
+ //WhereGroup(func(q *orm.Query) (*orm.Query, error) {
+ // q = q.WhereOr(`to LIKE '%` + listName + `@lists.gentoo.org%'`).
+ // WhereOr(`cc LIKE '%` + listName + `@lists.gentoo.org%'`).
+ // WhereOr(`to LIKE '%` + listName + `@gentoo.org%'`).
+ // WhereOr(`cc LIKE '%` + listName + `@gentoo.org%'`)
+ // return q, nil
+ //}).
ColumnExpr("to_char(date, 'YYYY-MM') AS combined_date").
ColumnExpr("count(*) AS message_count").
Group("combined_date").
diff --git a/pkg/app/list/threads.go b/pkg/app/list/threads.go
index 33ade3c..c069673 100644
--- a/pkg/app/list/threads.go
+++ b/pkg/app/list/threads.go
@@ -32,22 +32,21 @@ func Threads(w http.ResponseWriter, r *http.Request) {
var messages []*models.Message
query := database.DBCon.Model(&messages).
- Column("id", "headers", "date").
+ Column("id", "subject", "from", "date").
Where("to_char(date, 'YYYY-MM') = ?", combinedDate).
- Where(`NOT headers::jsonb ? 'References'`).
- Where(`NOT headers::jsonb ? 'In-Reply-To'`).
+ Where(`starts_thread = TRUE`).
WhereGroup(func(q *orm.Query) (*orm.Query, error) {
- q = q.WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE '[` + listName + `]%'`).
- WhereOr(`(headers::jsonb->>'Subject')::jsonb->>0 LIKE 'Re: [` + listName + `]%'`)
- return q, nil
- }).
- WhereGroup(func(q *orm.Query) (*orm.Query, error) {
- q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@lists.gentoo.org%'`).
- WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@lists.gentoo.org%'`).
- WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@gentoo.org%'`).
- WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@gentoo.org%'`)
+ q = q.WhereOr(`subject LIKE '[` + listName + `]%'`).
+ WhereOr(`subject LIKE 'Re: [` + listName + `]%'`)
return q, nil
}).
+ //WhereGroup(func(q *orm.Query) (*orm.Query, error) {
+ // q = q.WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@lists.gentoo.org%'`).
+ // WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@lists.gentoo.org%'`).
+ // WhereOr(`headers::jsonb->>'To' LIKE '%` + listName + `@gentoo.org%'`).
+ // WhereOr(`headers::jsonb->>'Cc' LIKE '%` + listName + `@gentoo.org%'`)
+ // return q, nil
+ //}).
Order("date DESC")
messagesCount, _ := query.Count()