From d800dc471e9a54db71358b7c5b89825780ea3920 Mon Sep 17 00:00:00 2001 From: aksonov Date: Wed, 16 Aug 2017 15:53:08 +0200 Subject: [PATCH 1/2] Persist bot information to avoid bot reloading from the server next time (and cover photo flickering), clear events after load #1093 --- ios/Podfile.lock | 12 ++++++------ src/factory/botFactory.js | 9 ++++++++- src/model/EventBot.js | 2 ++ src/model/model.js | 9 ++++++++- src/store/eventStore.js | 10 +++++----- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 76e4559b4..48f5e1549 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -8,13 +8,13 @@ PODS: - CocoaLumberjack/Default (3.2.0) - CocoaLumberjack/Extensions (3.2.0): - CocoaLumberjack/Default - - CodePush (4.1.0): - - CodePush/Core (= 4.1.0) - - CodePush/SSZipArchive (= 4.1.0) + - CodePush (5.0.0): + - CodePush/Core (= 5.0.0) + - CodePush/SSZipArchive (= 5.0.0) - React - - CodePush/Core (4.1.0): + - CodePush/Core (5.0.0): - React - - CodePush/SSZipArchive (4.1.0): + - CodePush/SSZipArchive (5.0.0): - React - KissXML (5.1.2): - KissXML/Core (= 5.1.2) @@ -254,7 +254,7 @@ CHECKOUT OPTIONS: SPEC CHECKSUMS: CocoaAsyncSocket: e0a7e93b2ffa411592ff87e58524fbbc9b95b4fa CocoaLumberjack: 9b4aed7073d242f29cc2f62068d995faf67f703a - CodePush: '098e7c7405113c335374ac3219f30ab7656639b6' + CodePush: '089e3da41b5040ba0ef89aa5d485f720ee4d5862' KissXML: 246c842586bb77110e04fb88e19376d96245c856 Mixpanel: 4b8e81c1d887d31bf72692a5f94d3e50019fce01 QBImagePickerController: d54cf93db6decf26baf6ed3472f336ef35cae022 diff --git a/src/factory/botFactory.js b/src/factory/botFactory.js index d86c14880..8fdbfe386 100644 --- a/src/factory/botFactory.js +++ b/src/factory/botFactory.js @@ -6,15 +6,22 @@ import Bot, {LOCATION, IMAGE, NOTE} from '../model/Bot'; import Utils from '../store/xmpp/utils'; import * as log from '../utils/log'; +import Bots from '../model/Bots'; @autobind class BotFactory { - @observable bots: {string: Bot} = {}; + bots: {string: Bot} = {}; constructor() { log.log('CREATE BOTFACTORY', {level: log.levels.DEBUG}); } + load(bots: Bots) { + for (let i = 0; i < bots._list.length; i++) { + this.bots[bots._list[i].id] = bots._list[i]; + } + } + remove(bot) { log.log('REMOVE BOT FROM FACTORY', bot.id, {level: log.levels.DEBUG}); delete this.bots[bot.id]; diff --git a/src/model/EventBot.js b/src/model/EventBot.js index 21d6c56be..c76ee313e 100644 --- a/src/model/EventBot.js +++ b/src/model/EventBot.js @@ -8,6 +8,7 @@ import Profile from './Profile'; import moment from 'moment'; import autobind from 'autobind-decorator'; import factory from '../factory/botFactory'; +import model from '../model/model'; // http://momentjs.com/docs/#/customization/relative-time/ moment.updateLocale('en', { @@ -69,6 +70,7 @@ export default class EventBot extends Event { this._id = id; if (botId && server) { this.bot = factory.create({id: botId, server}); + model.eventBots.add(this.bot); } if (time) { this.time = time; diff --git a/src/model/model.js b/src/model/model.js index 154e7963e..8c062ea1c 100644 --- a/src/model/model.js +++ b/src/model/model.js @@ -21,7 +21,9 @@ export class Model { @observable chats: Chats = new Chats(); @observable followingBots: Bots = new Bots(); @observable ownBots: Bots = new Bots(); - @observable geoBots = new Bots(); + @observable geoBots: Bots = new Bots(); + // event bots is list of bots used by Home Stream. We will persist it to avoid reloading of all bots + @observable eventBots: Bots = new Bots(); @observable friends: FriendList = new FriendList(); @observable profile: Profile; @observable user: ?string; @@ -53,6 +55,7 @@ export class Model { this.friends.clear(); this.ownBots.clear(); this.followingBots.clear(); + this.eventBots.clear(); this.geoBots.clear(); this.password = undefined; this.user = undefined; @@ -72,6 +75,9 @@ export class Model { if (d.messages) { messageFactory.load(d.messages); } + botFactory.load(d.eventBots); + botFactory.load(d.ownBots); + botFactory.load(d.followingBots); for (const key of Object.keys(d)) { this[key] = d[key]; } @@ -111,6 +117,7 @@ createModelSchema(Model, { messages: list(child(Message)), followingBots: child(Bots), ownBots: child(Bots), + eventBots: child(Bots), chats: child(Chats), profile: child(Profile), events: child(EventList), diff --git a/src/store/eventStore.js b/src/store/eventStore.js index 978bf5527..d937c19f9 100644 --- a/src/store/eventStore.js +++ b/src/store/eventStore.js @@ -124,11 +124,11 @@ export class EventStore { const data = await home.items(); runInAction(() => { - // @NOTE: don't clear the list...use the cache! - // if (data.items.length) { - // model.events.clear(); - // console.log('& clear', model.events); - // } + // need to clear events to avoid overloading of memory/disk for many events + if (data.items.length) { + model.events.clear(); + model.eventBots.clear(); + } if (data.count <= model.events.list.length) { model.events.finished = true; } From cec7c5e5479531a3fd6bd52439920eac636a7efe Mon Sep 17 00:00:00 2001 From: aksonov Date: Wed, 16 Aug 2017 15:55:56 +0200 Subject: [PATCH 2/2] revert podfile (part of other ticket) --- ios/Podfile.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 48f5e1549..76e4559b4 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -8,13 +8,13 @@ PODS: - CocoaLumberjack/Default (3.2.0) - CocoaLumberjack/Extensions (3.2.0): - CocoaLumberjack/Default - - CodePush (5.0.0): - - CodePush/Core (= 5.0.0) - - CodePush/SSZipArchive (= 5.0.0) + - CodePush (4.1.0): + - CodePush/Core (= 4.1.0) + - CodePush/SSZipArchive (= 4.1.0) - React - - CodePush/Core (5.0.0): + - CodePush/Core (4.1.0): - React - - CodePush/SSZipArchive (5.0.0): + - CodePush/SSZipArchive (4.1.0): - React - KissXML (5.1.2): - KissXML/Core (= 5.1.2) @@ -254,7 +254,7 @@ CHECKOUT OPTIONS: SPEC CHECKSUMS: CocoaAsyncSocket: e0a7e93b2ffa411592ff87e58524fbbc9b95b4fa CocoaLumberjack: 9b4aed7073d242f29cc2f62068d995faf67f703a - CodePush: '089e3da41b5040ba0ef89aa5d485f720ee4d5862' + CodePush: '098e7c7405113c335374ac3219f30ab7656639b6' KissXML: 246c842586bb77110e04fb88e19376d96245c856 Mixpanel: 4b8e81c1d887d31bf72692a5f94d3e50019fce01 QBImagePickerController: d54cf93db6decf26baf6ed3472f336ef35cae022