Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9ce4ba8
Renamed attachments to files
pzduniak Feb 8, 2015
239d6c5
EVERYONE LOVES YAML
pzduniak Feb 9, 2015
9f98d51
Fixed attachment tests
pzduniak Feb 9, 2015
24e123d
Database setup fix
pzduniak Feb 9, 2015
fb5cd2a
Thread count per label
pzduniak Feb 9, 2015
072718e
New information added to the events
pzduniak Feb 10, 2015
6e43dde
Prevent thread updates from dropping labels
pzduniak Feb 12, 2015
a666f03
New emails model; disabled internal mailing
pzduniak Feb 14, 2015
278e47a
Fixed slack integration
pzduniak Feb 14, 2015
945df55
Uncomment email queueing
pzduniak Feb 15, 2015
dbbddc8
Subject to name
pzduniak Feb 15, 2015
5f9bffd
Removed subject from the model
pzduniak Feb 15, 2015
01f5e86
Subject hashes
pzduniak Feb 18, 2015
fed4943
Subject hash index
pzduniak Feb 19, 2015
05b904c
Subject hashes
pzduniak Feb 20, 2015
bb46f03
Added manifests to emails.List
pzduniak Feb 20, 2015
2c7ee87
List with manifests query fix
pzduniak Feb 20, 2015
1f383ea
oops
pzduniak Feb 20, 2015
2948cbb
Fixed the thread query
pzduniak Feb 20, 2015
e03a489
pls work
pzduniak Feb 20, 2015
c7e916a
I didn't expect that to be the issue
pzduniak Feb 20, 2015
a5206a1
Added a gorethink tag definition
pzduniak Feb 20, 2015
5dc4a05
gorethink sucks
pzduniak Feb 20, 2015
f9718cd
Manifest in threads.get
pzduniak Feb 20, 2015
017ddda
Ordering fix
pzduniak Feb 20, 2015
cf7f9ea
Fixed attachments count query
pzduniak Feb 21, 2015
85b78a0
Added raw error logging to NATS pushing
pzduniak Feb 24, 2015
144ebb4
Swapped out NATS for nsq
pzduniak Feb 25, 2015
1cc1042
Fixed tests
pzduniak Feb 25, 2015
7646249
huge hack
pzduniak Feb 25, 2015
1feaafd
Removed .Stop() from nsq code
pzduniak Feb 25, 2015
81fad1d
Remove queued emails from emails list
pzduniak Feb 26, 2015
1a25045
Added utility field to the account model
pzduniak Mar 1, 2015
6ff377f
Merge pull request #92 from lavab/develop
pzduniak Mar 1, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
- GOPATH=/var/cache/drone
services:
- redis
- apcera/gnatsd
- mikedewar/nsqd
- dockerfile/rethinkdb
script:
- pip install fabric
Expand All @@ -18,9 +18,9 @@ script:
- "if [ \"$DRONE_BRANCH\" = \"develop\" ]; then fab -H bart.lavaboom.io:36467 deploy; fi"
notify:
slack:
- webhook_url: $$SLACK_URL
- channel: $$SLACK_CHANNEL
- username: lavadrone
- on_started: true
- on_success: true
- on_failure: true
webhook_url: $$SLACK_URL
channel: $$SLACK_CHANNEL
username: lavadrone
on_started: true
on_success: true
on_failure: true
40 changes: 0 additions & 40 deletions circle.yml

This file was deleted.

6 changes: 3 additions & 3 deletions db/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ var (
var tableIndexes = map[string][]string{
"accounts": []string{"name"},
"contacts": []string{"owner"},
"emails": []string{"owner", "label_ids"},
"emails": []string{"owner", "label_ids", "date_created", "thread"},
"files": []string{"owner"},
"keys": []string{"owner", "key_id"},
"labels": []string{"owner"},
"reservations": []string{"email", "name"},
"threads": []string{"owner"},
"threads": []string{"owner", "subject_hash"},
"tokens": []string{"owner"},
"attachments": []string{"owner"},
}

// List of names of databases
Expand Down
95 changes: 0 additions & 95 deletions db/table_attachments.go

This file was deleted.

23 changes: 22 additions & 1 deletion db/table_emails.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (e *EmailsTable) List(
filter["thread"] = thread
}

term := e.GetTable().Filter(filter)
term := e.GetTable().Filter(filter).Filter(gorethink.Not(gorethink.Row.Field("status").Eq(gorethink.Expr("queued"))))

// If sort array has contents, parse them and add to the term
if sort != nil && len(sort) > 0 {
Expand Down Expand Up @@ -128,3 +128,24 @@ func (e *EmailsTable) DeleteByThread(id string) error {
"thread": id,
})
}

func (e *EmailsTable) GetThreadManifest(thread string) (string, error) {
cursor, err := e.GetTable().
GetAllByIndex("thread", thread).
OrderBy("date_created").
Limit(1).
Pluck("manifest").
Field("manifest").
Run(e.GetSession())
if err != nil {
return "", err
}

var manifest string
err = cursor.One(&manifest)
if err != nil {
return "", err
}

return manifest, nil
}
95 changes: 95 additions & 0 deletions db/table_files.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package db

import (
"github.com/lavab/api/models"

"github.com/dancannon/gorethink"
)

type FilesTable struct {
RethinkCRUD
Emails *EmailsTable
}

func (f *FilesTable) GetFile(id string) (*models.File, error) {
var result models.File

if err := f.FindFetchOne(id, &result); err != nil {
return nil, err
}

return &result, nil
}

func (f *FilesTable) GetOwnedBy(id string) ([]*models.File, error) {
var result []*models.File

err := f.WhereAndFetch(map[string]interface{}{
"owner": id,
}, &result)
if err != nil {
return nil, err
}

return result, nil
}

func (f *FilesTable) DeleteOwnedBy(id string) error {
return f.Delete(map[string]interface{}{
"owner": id,
})
}

func (f *FilesTable) GetEmailFiles(id string) ([]*models.File, error) {
email, err := f.Emails.GetEmail(id)
if err != nil {
return nil, err
}

query, err := f.Emails.GetTable().Filter(func(row gorethink.Term) gorethink.Term {
return gorethink.Expr(email.Files).Contains(row.Field("id"))
}).GetAll().Run(f.Emails.GetSession())
if err != nil {
return nil, err
}

var result []*models.File
err = query.All(&result)
if err != nil {
return nil, err
}

return result, nil
}

func (f *FilesTable) CountByEmail(id string) (int, error) {
query, err := f.GetTable().GetAllByIndex("owner", id).Count().Run(f.GetSession())
if err != nil {
return 0, err
}

var result int
err = query.One(&result)
if err != nil {
return 0, err
}

return result, nil
}

func (f *FilesTable) CountByThread(id ...interface{}) (int, error) {
query, err := f.GetTable().Filter(func(row gorethink.Term) gorethink.Term {
return gorethink.Table("emails").GetAllByIndex("thread", id...).Field("files").Contains(row.Field("id"))
}).Count().Run(f.GetSession())
if err != nil {
return 0, err
}

var result int
err = query.One(&result)
if err != nil {
return 0, err
}

return result, nil
}
19 changes: 13 additions & 6 deletions db/table_threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,16 @@ func (t *ThreadsTable) List(
row.Field("labels").Contains(label),
)
})
}

if owner != "" && label == "" {
} else if owner != "" && label == "" {
term = t.GetTable().Filter(map[string]interface{}{
"owner": owner,
})
}

if owner == "" && label != "" {
} else if owner == "" && label != "" {
term = t.GetTable().Filter(func(row gorethink.Term) gorethink.Term {
return row.Field("labels").Contains(label)
})
} else {
term = t.GetTable()
}

// If sort array has contents, parse them and add to the term
Expand Down Expand Up @@ -103,6 +101,15 @@ func (t *ThreadsTable) List(
term = term.Slice(offset, offset+limit)
}

// Add manifests
term = term.InnerJoin(gorethink.Db(t.GetDBName()).Table("emails").Pluck("thread", "manifest"), func(thread gorethink.Term, email gorethink.Term) gorethink.Term {
return thread.Field("id").Eq(email.Field("thread"))
}).Without(map[string]interface{}{
"right": map[string]interface{}{
"thread": true,
},
}).Zip()

// Run the query
cursor, err := term.Run(t.GetSession())
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type Flags struct {
RethinkDBKey string
RethinkDBDatabase string

NATSAddress string
LookupdAddress string
NSQdAddress string

YubiCloudID string
YubiCloudKey string
Expand Down
10 changes: 5 additions & 5 deletions env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package env

import (
"github.com/Sirupsen/logrus"
"github.com/apcera/nats"
"github.com/bitly/go-nsq"
"github.com/dancannon/gorethink"

"github.com/lavab/api/cache"
Expand Down Expand Up @@ -33,12 +33,12 @@ var (
Emails *db.EmailsTable
// Labels is the global instance of LabelsTable
Labels *db.LabelsTable
// Attachments is the global instance of AttachmentsTable
Attachments *db.AttachmentsTable
// Files is the global instance of FilesTable
Files *db.FilesTable
// Threads is the global instance of ThreadsTable
Threads *db.ThreadsTable
// Factors contains all currently registered factors
Factors map[string]factor.Factor
// NATS is the encoded connection to the NATS queue
NATS *nats.EncodedConn
// Producer is the nsq producer used to send messages to other components of the system
Producer *nsq.Producer
)
Loading