Skip to content

Commit bcca19b

Browse files
authored
Merge pull request #1839 from floccusaddon/refactor/partial-set-data-with-lock
refactor(Account#setData): Accept partial data and use lock to set data
2 parents 4f00062 + ccc9c86 commit bcca19b

File tree

8 files changed

+69
-61
lines changed

8 files changed

+69
-61
lines changed

ios/App/App.xcodeproj/project.pbxproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@
363363
INFOPLIST_KEY_NSHumanReadableCopyright = "";
364364
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
365365
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
366-
MARKETING_VERSION = 5.4.0;
366+
MARKETING_VERSION = 5.4.1;
367367
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
368368
MTL_FAST_MATH = YES;
369369
PRODUCT_BUNDLE_IDENTIFIER = "org.handmadeideas.floccus.new-bookmark";
@@ -397,7 +397,7 @@
397397
INFOPLIST_KEY_NSHumanReadableCopyright = "";
398398
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
399399
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks";
400-
MARKETING_VERSION = 5.4.0;
400+
MARKETING_VERSION = 5.4.1;
401401
MTL_FAST_MATH = YES;
402402
PRODUCT_BUNDLE_IDENTIFIER = "org.handmadeideas.floccus.new-bookmark";
403403
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -459,7 +459,7 @@
459459
GCC_WARN_UNUSED_FUNCTION = YES;
460460
GCC_WARN_UNUSED_VARIABLE = YES;
461461
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
462-
MARKETING_VERSION = 5.4.0;
462+
MARKETING_VERSION = 5.4.1;
463463
MTL_ENABLE_DEBUG_INFO = YES;
464464
ONLY_ACTIVE_ARCH = YES;
465465
SDKROOT = iphoneos;
@@ -511,7 +511,7 @@
511511
GCC_WARN_UNUSED_FUNCTION = YES;
512512
GCC_WARN_UNUSED_VARIABLE = YES;
513513
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
514-
MARKETING_VERSION = 5.4.0;
514+
MARKETING_VERSION = 5.4.1;
515515
MTL_ENABLE_DEBUG_INFO = NO;
516516
SDKROOT = iphoneos;
517517
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
@@ -537,7 +537,7 @@
537537
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
538538
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
539539
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
540-
MARKETING_VERSION = 5.4.0;
540+
MARKETING_VERSION = 5.4.1;
541541
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
542542
PRODUCT_BUNDLE_IDENTIFIER = org.handmadeideas.floccus;
543543
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -567,7 +567,7 @@
567567
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.productivity";
568568
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
569569
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
570-
MARKETING_VERSION = 5.4.0;
570+
MARKETING_VERSION = 5.4.1;
571571
PRODUCT_BUNDLE_IDENTIFIER = org.handmadeideas.floccus;
572572
PRODUCT_NAME = "$(TARGET_NAME)";
573573
PROVISIONING_PROFILE_SPECIFIER = "";

ios/App/PrivacyInfo.xcprivacy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>NSPrivacyAccessedAPITypes</key>
6+
<array>
7+
<dict>
8+
<key>NSPrivacyAccessedAPIType</key>
9+
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
10+
<key>NSPrivacyAccessedAPITypeReasons</key>
11+
<array>
12+
<string>CA92.1</string>
13+
</array>
14+
</dict>
15+
</array>
16+
</dict>
17+
</plist>

src/lib/Account.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Mappings from './Mappings'
1313
import { isTest } from './isTest'
1414
import CachingAdapter from './adapters/Caching'
1515
import * as Sentry from '@sentry/vue'
16+
import AsyncLock from 'async-lock'
1617

1718
declare const DEBUG: boolean
1819

@@ -28,6 +29,8 @@ AdapterFactory.register('fake', async() => (await import('./adapters/Fake')).def
2829
// 2h
2930
const LOCK_TIMEOUT = 1000 * 60 * 60 * 2
3031

32+
const dataLock = new AsyncLock()
33+
3134
export default class Account {
3235
static cache = {}
3336
static singleton : IAccount
@@ -96,7 +99,7 @@ export default class Account {
9699
}
97100

98101
getData():IAccountData {
99-
const defaults = {
102+
const data = {
100103
localRoot: null,
101104
strategy: 'default' as TAccountStrategy,
102105
syncInterval: 15,
@@ -106,9 +109,9 @@ export default class Account {
106109
label: '',
107110
errorCount: 0,
108111
clickCountEnabled: false,
112+
...this.server.getData()
109113
}
110-
const data = Object.assign(defaults, this.server.getData())
111-
if (data.type === 'nextcloud-folders') {
114+
if ('type' in data && data.type === 'nextcloud-folders') {
112115
data.type = 'nextcloud-bookmarks'
113116
}
114117
return data
@@ -122,9 +125,12 @@ export default class Account {
122125
return this.server
123126
}
124127

125-
async setData(data:IAccountData):Promise<void> {
126-
await this.storage.setAccountData(data, null)
127-
this.server.setData(data)
128+
async setData(data:Partial<IAccountData>):Promise<void> {
129+
await dataLock.acquire(this.id, async() => {
130+
const d = {...this.server.getData(), ...data}
131+
await this.storage.setAccountData(d, null)
132+
this.server.setData(d)
133+
})
128134
}
129135

130136
async updateFromStorage():Promise<void> {
@@ -163,7 +169,7 @@ export default class Account {
163169
Logger.log('Starting sync process for account ' + this.getLabel())
164170
Sentry.setUser({ id: this.id })
165171
this.syncing = true
166-
await this.setData({ ...this.getData(), syncing: 0.05, scheduled: false, error: null })
172+
await this.setData({ syncing: 0.05, scheduled: false, error: null })
167173

168174
if (!(await this.isInitialized())) {
169175
await this.init()
@@ -184,7 +190,6 @@ export default class Account {
184190
status = await this.server.onSyncStart(false, true)
185191
} else {
186192
await this.setData({
187-
...this.getData(),
188193
error: null,
189194
syncing: false,
190195
scheduled: strategy || this.getData().strategy
@@ -277,7 +282,7 @@ export default class Account {
277282
await this.syncProcess.sync()
278283
}
279284

280-
await this.setData({ ...this.getData(), scheduled: false, syncing: 1 })
285+
await this.setData({ scheduled: false, syncing: 1 })
281286

282287
// update cache
283288
const cache = (await localResource.getBookmarksTree()).clone(false)
@@ -297,7 +302,6 @@ export default class Account {
297302

298303
await this.storage.setCurrentContinuation(null)
299304
await this.setData({
300-
...this.getData(),
301305
error: null,
302306
errorCount: 0,
303307
syncing: false,
@@ -326,7 +330,6 @@ export default class Account {
326330
}
327331

328332
await this.setData({
329-
...this.getData(),
330333
error: message,
331334
errorCount: this.getData().errorCount + 1,
332335
syncing: false,
@@ -365,7 +368,7 @@ export default class Account {
365368
if (!this.syncing) {
366369
return
367370
}
368-
await this.setData({ ...this.getData(), syncing: progress })
371+
await this.setData({ syncing: progress })
369372
if (!this.syncProcess) {
370373
return
371374
}

src/lib/browser/BrowserController.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ export default class BrowserController {
302302

303303
const status = await this.getStatus()
304304
if (status === STATUS_SYNCING) {
305-
await account.setData({ ...account.getData(), scheduled: account.getData().scheduled || true })
305+
await account.setData({ scheduled: account.getData().scheduled || true })
306306
return
307307
}
308308

@@ -316,7 +316,7 @@ export default class BrowserController {
316316
async scheduleAll() {
317317
const accounts = await Account.getAllAccounts()
318318
for (const account of accounts) {
319-
await account.setData({...account.getData(), scheduled: true})
319+
await account.setData({ scheduled: true })
320320
}
321321
this.updateStatus()
322322
}
@@ -325,7 +325,7 @@ export default class BrowserController {
325325
let account = await Account.get(accountId)
326326
// Avoid starting it again automatically
327327
if (!keepEnabled) {
328-
await account.setData({ ...account.getData(), enabled: false })
328+
await account.setData({ enabled: false })
329329
}
330330
await account.cancelSync()
331331
}
@@ -421,7 +421,6 @@ export default class BrowserController {
421421
accounts.map(async acc => {
422422
if (acc.getData().syncing) {
423423
await acc.setData({
424-
...acc.getData(),
425424
syncing: false,
426425
scheduled: acc.getData().enabled,
427426
})

src/lib/native/NativeController.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export default class NativeController {
120120

121121
const status = await this.getStatus()
122122
if (status === STATUS_SYNCING) {
123-
await account.setData({ ...account.getData(), scheduled: account.getData().scheduled || true })
123+
await account.setData({ scheduled: account.getData().scheduled || true })
124124
return
125125
}
126126

@@ -135,7 +135,7 @@ export default class NativeController {
135135
let account = await Account.get(accountId)
136136
// Avoid starting it again automatically
137137
if (!keepEnabled) {
138-
await account.setData({ ...account.getData(), enabled: false })
138+
await account.setData({ enabled: false })
139139
}
140140
await account.cancelSync()
141141
}
@@ -202,7 +202,6 @@ export default class NativeController {
202202
accounts.map(async acc => {
203203
if (acc.getData().syncing) {
204204
await acc.setData({
205-
...acc.getData(),
206205
syncing: false,
207206
scheduled: false,
208207
})

0 commit comments

Comments
 (0)