Skip to content

Commit

Permalink
Merge pull request #13 from planetary-social/rb-performance-tweaks
Browse files Browse the repository at this point in the history
Change loading order to give UI which works faster
  • Loading branch information
rabble authored Mar 10, 2020
2 parents 6078b6a + b772719 commit 22ab0b8
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 37 deletions.
4 changes: 3 additions & 1 deletion Source/App/AppController+BackgroundSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ extension AppController {
if notificationsOnly {
self?.syncNotifications(task: task, completion: completion)
} else {
self?.syncEverything(task: task, completion: completion)


//self?.syncEverything(task: task, completion: completion)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Controller/LaunchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class LaunchViewController: UIViewController {

// transition to main app UI
// note that delay which is to help the loginAndSync() call get content
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
// removing delay... let syncing happen in the background
DispatchQueue.main.async {
AppController.shared.showMainViewController(animated: true)
}
}
Expand Down
15 changes: 10 additions & 5 deletions Source/GoBot/GoBot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@ class GoBot: Bot {
}

func login(network: NetworkKey, hmacKey: HMACKey?, secret: Secret, completion: @escaping ErrorCompletion) {

// is this saying we need to be the main thread to login? -rabble
Thread.assertIsMainThread()

self.queue.async {
var err: Error? = nil
defer {
DispatchQueue.main.async {
Expand Down Expand Up @@ -127,14 +129,17 @@ class GoBot: Bot {
Log.unexpected(.botError, "\(#function) warning: database still open")
}

if !self.bot.repoFSCK(.FeedLength) {
err = GoBotError.unexpectedFault("login repo FSCK failed")
return
}
// don't check for fsck on login, we'll be able to check it later
// to see if it's working - rabble
//if !self.bot.repoFSCK(.FeedLength) {
// err = GoBotError.unexpectedFault("login repo FSCK failed")
// return
//}

// TODO this does not always get set in time
// TODO maybe this should be done in defer?
self._identity = secret.identity
}
return
}

Expand Down
5 changes: 3 additions & 2 deletions Source/GoBot/ViewDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import SQLite
// schema migration handling
extension Connection {
public var userVersion: Int32 {
get { return Int32(try! scalar("PRAGMA user_version") as! Int64)}
set { try! run("PRAGMA user_version = \(newValue)") }
get { return Int32(try! scalar("PRAGMA user_version;") as! Int64)}
set { try! run("PRAGMA user_version = \(newValue);") }
}
}

Expand Down Expand Up @@ -196,6 +196,7 @@ class ViewDatabase {
self.dbPath = "\(path)/schema-built\(ViewDatabase.schemaVersion).sqlite"
let db = try Connection(self.dbPath) // Q: use proper fs.join API instead of string interpolation?
self.openDB = db
try db.execute("PRAGMA journal_mode = WAL;")

// db.trace { Log.info($0) } // print all the statements

Expand Down
3 changes: 2 additions & 1 deletion UnitTests/ContentTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class ContentTests: XCTestCase {
XCTAssertTrue(content?.assertValid() ?? false)

// models that SHOULD NOT be encoded
case .address, .unknown, .unsupported: break
case .pub, .address, .unknown, .unsupported: break
}
}
} catch {
Expand Down Expand Up @@ -435,6 +435,7 @@ fileprivate extension Content {
case .address: return self.address != nil
case .contact: return self.contact != nil
case .dropContentRequest: return self.dropContentRequest != nil
case .pub: return self.pub != nil
case .post: return self.post != nil
case .vote: return self.vote != nil
case .unsupported: return false
Expand Down
5 changes: 5 additions & 0 deletions go-ssb-bindings/api-ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ func ssbBotInit(config string, notifyFn uintptr) bool {
err = errors.Wrap(err, "BotInit: failed to open view database")
return false
}
_, err = viewDB.Exec("PRAGMA journal_mode=WAL;")
if err != nil {
err = errors.Wrap(err, "BotInit: failed to switch mode to WAL")
return false
}

// key should be stored in keychain anyway
os.Remove(r.GetPath("secret"))
Expand Down
5 changes: 3 additions & 2 deletions go-ssb-bindings/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func ssbConnectPeers(count uint32) bool {
}
close(newConns)

if err := wg.Wait(); err != nil {
err = wg.Wait()
close(connErrs)
if err != nil {
retErr = errors.Wrap(err, "waiting for conn workers")
return false
}
close(connErrs)

return true
}
Expand Down
2 changes: 1 addition & 1 deletion go-ssb-bindings/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/mattn/go-sqlite3 v1.11.0
github.com/pkg/errors v0.9.1
go.cryptoscope.co/luigi v0.3.6-0.20200131144242-3256b54e72c8
go.cryptoscope.co/margaret v0.1.4
go.cryptoscope.co/margaret v0.1.5
go.cryptoscope.co/muxrpc v1.5.4-0.20200212114344-0403d7496950 // indirect
go.cryptoscope.co/netwrap v0.1.1
go.cryptoscope.co/ssb v0.0.0-20200304093142-4310d5a24560
Expand Down
2 changes: 2 additions & 0 deletions go-ssb-bindings/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ go.cryptoscope.co/margaret v0.0.8/go.mod h1:VbP0bqavqW5osTmdNvgukrqtmqvZC5sXyPSB
go.cryptoscope.co/margaret v0.0.12-0.20190912103626-34323ad497f4/go.mod h1:3rt+RmZTFZEgfvFxz0ZPDBIWtLJOouWtzV6YbBl6sek=
go.cryptoscope.co/margaret v0.1.4 h1:VdwbAAChHj6M1wHzqGGpJ94hSaPMaDKnAzuHZE4zVa8=
go.cryptoscope.co/margaret v0.1.4/go.mod h1:9anofnVTwgMMNY1zENRRZHSpjiEDEBZg40CIaX4raPY=
go.cryptoscope.co/margaret v0.1.5 h1:2Yg/WKoqNt81cfvtT0bJNmwv+ljiRfM5mG5oDSPDCxU=
go.cryptoscope.co/margaret v0.1.5/go.mod h1:9anofnVTwgMMNY1zENRRZHSpjiEDEBZg40CIaX4raPY=
go.cryptoscope.co/muxrpc v1.4.1-0.20190910185819-a3119150878e/go.mod h1:dV/i300s3OxZKI0YPlY/hG7w2y9TFgu3oQkNDXBoMQY=
go.cryptoscope.co/muxrpc v1.5.4-0.20191205134222-b1563255bffa h1:wwBK13xg2akKHUP3oBa4COx1NMCxUPZpqlCz4EPx29A=
go.cryptoscope.co/muxrpc v1.5.4-0.20191205134222-b1563255bffa/go.mod h1:kB8EGlRBgr5M8E80CKaTxC2Ga8OCMLUVnw8YNiFSVrw=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func Open(name string, cdc margaret.Codec) (*offsetLog, error) {
codec: cdc,
}

err = log.checkConsistency()
err = log.checkJournal()
if err != nil {
return nil, errors.Wrap(err, "offset2: integrity error")
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func (log *offsetLog) checkJournal() error {
return errors.Wrap(err, "recover: could not overwrite journal with offset seq")
}

if err := log.checkConsistency(); err != nil {
if err := log.CheckConsistency(); err != nil {
return errors.Wrap(err, "recover: check journal 2nd pass")
}
}
Expand Down Expand Up @@ -295,8 +295,8 @@ func (log *offsetLog) checkJournal() error {
return nil
}

// checkConsistency is an fsck for the offset log.
func (log *offsetLog) checkConsistency() error {
// CheckConsistency is an fsck for the offset log.
func (log *offsetLog) CheckConsistency() error {
err := log.checkJournal()
if err != nil {
return errors.Wrap(err, "offset2: journal inconsistent")
Expand Down
21 changes: 1 addition & 20 deletions go-ssb-bindings/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ github.com/AndreasBriese/bbloom
# github.com/RoaringBitmap/roaring v0.4.21-0.20190925020156-96f2302555b6
github.com/RoaringBitmap/roaring
# github.com/cryptix/go v1.5.0
## explicit
github.com/cryptix/go/encodedTime
github.com/cryptix/go/logging
github.com/cryptix/go/logging/countconn
Expand All @@ -17,7 +16,6 @@ github.com/dgraph-io/badger/skl
github.com/dgraph-io/badger/table
github.com/dgraph-io/badger/y
# github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b
## explicit
github.com/dgryski/go-farm
# github.com/dustin/go-humanize v1.0.0
github.com/dustin/go-humanize
Expand All @@ -26,7 +24,6 @@ github.com/edsrzf/mmap-go
# github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2
github.com/glycerine/go-unsnap-stream
# github.com/go-kit/kit v0.9.0
## explicit
github.com/go-kit/kit/log
github.com/go-kit/kit/log/level
github.com/go-kit/kit/metrics
Expand All @@ -43,21 +40,18 @@ github.com/hashicorp/go-multierror
# github.com/keks/nocomment v0.0.0-20181007001506-30c6dcb4a472
github.com/keks/nocomment
# github.com/keks/persist v0.0.0-20191006175951-43c124092b8b
## explicit
github.com/keks/persist
# github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
github.com/kr/logfmt
# github.com/libp2p/go-reuseport v0.0.1
github.com/libp2p/go-reuseport
# github.com/mattn/go-sqlite3 v1.11.0
## explicit
github.com/mattn/go-sqlite3
# github.com/mschoch/smat v0.0.0-20160514031455-90eadee771ae
github.com/mschoch/smat
# github.com/philhofer/fwd v1.0.0
github.com/philhofer/fwd
# github.com/pkg/errors v0.9.1
## explicit
github.com/pkg/errors
# github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237
github.com/remyoudompheng/bigfft
Expand All @@ -72,11 +66,9 @@ go.cryptoscope.co/librarian
go.cryptoscope.co/librarian/badger
go.cryptoscope.co/librarian/mkv
# go.cryptoscope.co/luigi v0.3.6-0.20200131144242-3256b54e72c8
## explicit
go.cryptoscope.co/luigi
go.cryptoscope.co/luigi/mfr
# go.cryptoscope.co/margaret v0.1.4
## explicit
# go.cryptoscope.co/margaret v0.1.5
go.cryptoscope.co/margaret
go.cryptoscope.co/margaret/codec/msgpack
go.cryptoscope.co/margaret/internal/persist
Expand All @@ -88,11 +80,9 @@ go.cryptoscope.co/margaret/multilog/roaring
go.cryptoscope.co/margaret/multilog/roaring/mkv
go.cryptoscope.co/margaret/offset2
# go.cryptoscope.co/muxrpc v1.5.4-0.20200212114344-0403d7496950
## explicit
go.cryptoscope.co/muxrpc
go.cryptoscope.co/muxrpc/codec
# go.cryptoscope.co/netwrap v0.1.1
## explicit
go.cryptoscope.co/netwrap
# go.cryptoscope.co/secretstream v1.2.2-0.20200303151838-85cf020cfee6
go.cryptoscope.co/secretstream
Expand All @@ -101,7 +91,6 @@ go.cryptoscope.co/secretstream/internal/lo25519
go.cryptoscope.co/secretstream/secrethandshake
go.cryptoscope.co/secretstream/secrethandshake/internal/extra25519
# go.cryptoscope.co/ssb v0.0.0-20200304093142-4310d5a24560
## explicit
go.cryptoscope.co/ssb
go.cryptoscope.co/ssb/blobstore
go.cryptoscope.co/ssb/client
Expand Down Expand Up @@ -137,7 +126,6 @@ go.cryptoscope.co/ssb/sbot
# go.mindeco.de/ssb-gabbygrove v0.1.6
go.mindeco.de/ssb-gabbygrove
# go.mindeco.de/ssb-multiserver v0.0.0-20200302171328-987e421fadee
## explicit
go.mindeco.de/ssb-multiserver
# golang.org/x/crypto v0.0.0-20200303113948-2939d6771b24 => github.com/cryptix/golang_x_crypto v0.0.0-20200303113948-2939d6771b24
golang.org/x/crypto/blake2b
Expand All @@ -151,14 +139,11 @@ golang.org/x/crypto/nacl/secretbox
golang.org/x/crypto/poly1305
golang.org/x/crypto/salsa20/salsa
# golang.org/x/exp v0.0.0-20190912063710-ac5d2bfcbfe0
## explicit
golang.org/x/exp/rand
# golang.org/x/net v0.0.0-20190909003024-a7b16738d86b
## explicit
golang.org/x/net/internal/timeseries
golang.org/x/net/trace
# golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
## explicit
golang.org/x/sync/errgroup
# golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527
golang.org/x/sys/cpu
Expand All @@ -173,7 +158,6 @@ golang.org/x/text/internal/utf8internal
golang.org/x/text/runes
golang.org/x/text/transform
# gonum.org/v1/gonum v0.0.0-20190911200027-40d3308efe80
## explicit
gonum.org/v1/gonum/blas
gonum.org/v1/gonum/blas/blas64
gonum.org/v1/gonum/blas/cblas128
Expand Down Expand Up @@ -207,8 +191,6 @@ gonum.org/v1/gonum/lapack
gonum.org/v1/gonum/lapack/gonum
gonum.org/v1/gonum/lapack/lapack64
gonum.org/v1/gonum/mat
# gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e
## explicit
# modernc.org/fileutil v1.0.1-0.20191220121946-b2535a37172b
modernc.org/fileutil
# modernc.org/internal v1.0.0
Expand All @@ -225,4 +207,3 @@ modernc.org/mathutil
modernc.org/sortutil
# modernc.org/zappy v1.0.0
modernc.org/zappy
# golang.org/x/crypto => github.com/cryptix/golang_x_crypto v0.0.0-20200303113948-2939d6771b24

0 comments on commit 22ab0b8

Please sign in to comment.