mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-08-29 10:09:26 +02:00
Compare commits
6 Commits
fix/locked
...
fix-logger
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbcef9d44a | ||
|
|
b9aa49e17a | ||
|
|
bab65528db | ||
|
|
4a743d98b7 | ||
|
|
4b44c39ec8 | ||
|
|
a7d85cb3f6 |
@@ -16,8 +16,8 @@ GNU General Public License for more details.
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { MMKVLoader } from "react-native-mmkv-storage";
|
||||
import { initalize } from "@notesnook/core/dist/logger";
|
||||
import { MMKVLoader } from "react-native-mmkv-storage";
|
||||
import { KV } from "./storage";
|
||||
|
||||
const LoggerStorage = new MMKVLoader()
|
||||
@@ -26,4 +26,4 @@ const LoggerStorage = new MMKVLoader()
|
||||
|
||||
initalize(new KV(LoggerStorage));
|
||||
|
||||
export {};
|
||||
export { LoggerStorage };
|
||||
|
||||
@@ -90,6 +90,10 @@ export class KV {
|
||||
return this.storage.removeItem(key);
|
||||
}
|
||||
|
||||
async removeMulti(keys) {
|
||||
return this.storage.removeItems(...keys);
|
||||
}
|
||||
|
||||
async clear() {
|
||||
return this.storage.clearStore();
|
||||
}
|
||||
@@ -145,6 +149,7 @@ export default {
|
||||
clear: () => DefaultStorage.clear(),
|
||||
getAllKeys: () => DefaultStorage.getAllKeys(),
|
||||
writeMulti: (items) => DefaultStorage.writeMulti(items),
|
||||
removeMulti: (keys) => DefaultStorage.removeMulti(keys),
|
||||
encrypt,
|
||||
decrypt,
|
||||
decryptMulti,
|
||||
|
||||
@@ -327,7 +327,7 @@ PODS:
|
||||
- React-Core
|
||||
- react-native-keep-awake (1.2.0):
|
||||
- React-Core
|
||||
- react-native-mmkv-storage (0.10.0-alpha.9):
|
||||
- react-native-mmkv-storage (0.10.0-alpha.11):
|
||||
- MMKV (~> 1.3.1)
|
||||
- React
|
||||
- React-Core
|
||||
@@ -875,7 +875,7 @@ SPEC CHECKSUMS:
|
||||
react-native-image-resizer: 00ceb0e05586c7aadf061eea676957a6c2ec60fa
|
||||
react-native-in-app-review: db8bb167a5f238e7ceca5c242d6b36ce8c4404a4
|
||||
react-native-keep-awake: caee3ff89eaa21dfe29010f0d143566874a04441
|
||||
react-native-mmkv-storage: d4ad55ab411b7f0d4e6269d801b31821ef48970b
|
||||
react-native-mmkv-storage: e798639f91601896f1c84f4eb3d6f19af2f4a160
|
||||
react-native-netinfo: ccbe1085dffd16592791d550189772e13bf479e2
|
||||
react-native-notification-sounds: da78c828fe1bcbb92d8b505d5261890ed315ff39
|
||||
react-native-orientation: f1caf84d65f1a4fd4511a18f2b924e634ad7a628
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
"react-native-image-picker": "4.1.2",
|
||||
"react-native-in-app-review": "4.3.3",
|
||||
"react-native-keychain": "4.0.5",
|
||||
"react-native-mmkv-storage": "^0.10.0-alpha.9",
|
||||
"react-native-mmkv-storage": "^0.10.0-alpha.11",
|
||||
"react-native-modal-datetime-picker": "14.0.0",
|
||||
"react-native-navigation-bar-color": "2.0.2",
|
||||
"react-native-notification-sounds": "0.5.5",
|
||||
|
||||
456
apps/mobile/package-lock.json
generated
456
apps/mobile/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -70,6 +70,10 @@ export class NNStorage {
|
||||
return this.database.delete(key);
|
||||
}
|
||||
|
||||
removeMulti(keys: string[]) {
|
||||
return this.database.deleteMany(keys);
|
||||
}
|
||||
|
||||
clear() {
|
||||
return this.database.clear();
|
||||
}
|
||||
|
||||
@@ -48,6 +48,10 @@ export default class Storage {
|
||||
return this.storage.remove(key);
|
||||
}
|
||||
|
||||
removeMulti(keys) {
|
||||
return this.storage.removeMulti(keys);
|
||||
}
|
||||
|
||||
getAllKeys() {
|
||||
return this.storage.getAllKeys();
|
||||
}
|
||||
|
||||
@@ -59,8 +59,7 @@ class DatabaseLogWriter {
|
||||
*/
|
||||
constructor(storage) {
|
||||
this.storage = storage;
|
||||
this.key = new Date().toLocaleDateString();
|
||||
this.queue = {};
|
||||
this.queue = new Map();
|
||||
this.hasCleared = false;
|
||||
setInterval(() => {
|
||||
setTimeout(() => {
|
||||
@@ -74,34 +73,29 @@ class DatabaseLogWriter {
|
||||
}
|
||||
|
||||
push(message) {
|
||||
this.queue[`${this.key}:${message.timestamp}`] = message;
|
||||
}
|
||||
|
||||
async read() {
|
||||
const logKeys = await this.storage.getAllKeys();
|
||||
const keys = [];
|
||||
for (let key of logKeys) {
|
||||
if (key.startsWith(this.key)) keys.push(key);
|
||||
}
|
||||
return Object.values(await this.storage.readMulti(keys));
|
||||
const key = new Date(message.timestamp).toLocaleDateString();
|
||||
this.queue.set(`${key}:${message.timestamp}`, message);
|
||||
}
|
||||
|
||||
async flush() {
|
||||
if (Object.keys(this.queue).length === 0) return;
|
||||
const queueCopy = Object.entries(this.queue);
|
||||
this.queue = {};
|
||||
if (this.queue.size === 0) return;
|
||||
const queueCopy = Array.from(this.queue.entries());
|
||||
this.queue = new Map();
|
||||
|
||||
await this.storage.writeMulti(queueCopy);
|
||||
}
|
||||
|
||||
async rotate() {
|
||||
const logKeys = (await this.storage.getAllKeys()).sort();
|
||||
const keysToRemove = [];
|
||||
for (let key of logKeys) {
|
||||
const keyParts = key.split(":");
|
||||
if (keyParts.length === 1 || parseInt(keyParts[1]) < Date.now() - WEEK) {
|
||||
await this.storage.remove(key);
|
||||
keysToRemove.push(key);
|
||||
}
|
||||
}
|
||||
|
||||
if (keysToRemove.length) await this.storage.removeMulti(keysToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,42 +110,41 @@ class DatabaseLogManager {
|
||||
|
||||
async get() {
|
||||
const logKeys = await this.storage.getAllKeys();
|
||||
const logs = {};
|
||||
const logs = await this.storage.readMulti(logKeys);
|
||||
const logGroups = {};
|
||||
|
||||
for (const logKey of logKeys) {
|
||||
const keyParts = logKey.split(":");
|
||||
for (const [key, log] of logs) {
|
||||
const keyParts = key.split(":");
|
||||
if (keyParts.length === 1) continue;
|
||||
const key = keyParts[0];
|
||||
|
||||
const log = await this.storage.read(logKey, true);
|
||||
|
||||
if (!logs[key]) logs[key] = [];
|
||||
logs[key].push(log);
|
||||
const groupKey = keyParts[0];
|
||||
if (!logGroups[groupKey]) logGroups[groupKey] = [];
|
||||
logGroups[groupKey].push(log);
|
||||
}
|
||||
|
||||
return Object.keys(logs).map((key) => ({
|
||||
key: key,
|
||||
logs: logs[key]?.sort((a, b) => a.timestamp - b.timestamp)
|
||||
}));
|
||||
return Object.keys(logGroups)
|
||||
.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }))
|
||||
.map((key) => ({
|
||||
key,
|
||||
logs: logGroups[key]?.sort((a, b) => a.timestamp - b.timestamp)
|
||||
}));
|
||||
}
|
||||
|
||||
async clear() {
|
||||
const logKeys = await this.storage.getAllKeys();
|
||||
for (const key of logKeys) {
|
||||
await this.storage.remove(key);
|
||||
}
|
||||
await this.storage.removeMulti(logKeys);
|
||||
}
|
||||
|
||||
async delete(key) {
|
||||
const logKeys = await this.storage.getAllKeys();
|
||||
const keysToRemove = [];
|
||||
for (const logKey of logKeys) {
|
||||
const keyParts = logKey.split(":");
|
||||
if (keyParts.length === 1) continue;
|
||||
const currKey = keyParts[0];
|
||||
if (currKey === key) {
|
||||
await this.storage.remove(logKey);
|
||||
}
|
||||
if (currKey === key) keysToRemove.push(logKey);
|
||||
}
|
||||
if (keysToRemove.length) await this.storage.removeMulti(keysToRemove);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user