Migrate user data from old version of coracle

This commit is contained in:
Jonathan Staab 2023-03-15 11:40:16 -05:00
parent 7a85323b8f
commit 5138f14e00
5 changed files with 20 additions and 14 deletions

View File

@ -14,7 +14,7 @@
import {timedelta, shuffle, now, sleep} from "src/util/misc"
import {displayPerson, isLike} from "src/util/nostr"
import cmd from "src/agent/cmd"
import {onReady, relays} from "src/agent/tables"
import {onReady, relays, people} from "src/agent/tables"
import keys from "src/agent/keys"
import network from "src/agent/network"
import pool from "src/agent/pool"
@ -120,8 +120,19 @@
initializeRelayList()
if (user.getProfile()) {
loadAppData(user.getPubkey())
const pubkey = user.getPubkey()
if (pubkey) {
loadAppData(pubkey)
const person = people.get(pubkey)
// Temporary migration for version 0.2.18. We changed where user profile
// is stored, so if they appear to have an incomplete profile on page load,
// go ahead and copy the person record over.
if (person && user.getRelays().length === 0) {
user.profile.update($p => ({...$p, ...person}))
}
}
const interval = setInterval(async () => {

View File

@ -13,7 +13,7 @@ import {
hash,
} from "src/util/misc"
import {Tags, roomAttrs, isRelay, isShareableRelay, normalizeRelayUrl} from "src/util/nostr"
import {people, userEvents, relays, rooms, routes} from "src/agent/tables"
import {people, relays, rooms, routes} from "src/agent/tables"
import {uniqByUrl} from "src/agent/relays"
import user from "src/agent/user"
@ -25,15 +25,10 @@ const addHandler = (kind, f) => {
}
const processEvents = async events => {
const userPubkey = user.getPubkey()
const chunks = chunk(100, ensurePlural(events).filter(identity))
for (let i = 0; i < chunks.length; i++) {
for (const event of chunks[i]) {
if (event.pubkey === userPubkey) {
userEvents.put(event)
}
for (const handler of handlers[event.kind] || []) {
handler(event)
}

View File

@ -2,8 +2,8 @@ import {pluck, all, identity} from "ramda"
import {derived} from "svelte/store"
import {Table, listener, registry} from "src/agent/storage"
export const userEvents = new Table("userEvents", "id")
export const people = new Table("people", "pubkey")
// Temporarily put no upper bound on people for 0.2.18 migration
export const people = new Table("people", "pubkey", {maxEntries: 100000})
export const contacts = new Table("contacts", "pubkey")
export const rooms = new Table("rooms", "id")
export const alerts = new Table("alerts", "id")

View File

@ -3,7 +3,7 @@ import {max, find, pluck, propEq, partition, uniq} from "ramda"
import {derived} from "svelte/store"
import {createMap} from "hurdak/lib/hurdak"
import {synced, tryJson, now, timedelta} from "src/util/misc"
import {Tags, userKinds, isAlert, asDisplayEvent, findReplyId} from "src/util/nostr"
import {Tags, isAlert, asDisplayEvent, findReplyId} from "src/util/nostr"
import {getUserReadRelays} from "src/agent/relays"
import {alerts, contacts, rooms} from "src/agent/tables"
import {watch} from "src/agent/storage"
@ -173,7 +173,6 @@ const listen = async pubkey => {
delay: 10000,
relays: getUserReadRelays(),
filter: [
{kinds: userKinds, authors: [pubkey], since},
{kinds: [4], authors: [pubkey], since},
{kinds: [1, 7, 4, 9735], "#p": [pubkey], since},
{kinds: [42], "#e": roomIds, since},

View File

@ -16,7 +16,8 @@ export const loadAppData = async pubkey => {
// Start our listener, but don't wait for it
alerts.listen(pubkey)
// Make sure the user's network is loaded
// Make sure the user and their network is loaded
await network.loadPeople([pubkey], {force: true})
await network.loadPeople(getUserFollows())
}
}