Add first set of import/export APIs
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
// core:profiles/<scope>/<id>
|
||||
// cache:profiles/index/<identifier>/<value>
|
||||
|
||||
const profilesDBPath = "core:profiles/"
|
||||
const ProfilesDBPath = "core:profiles/"
|
||||
|
||||
var profileDB = database.NewInterface(&database.Options{
|
||||
Local: true,
|
||||
@@ -28,17 +28,17 @@ func makeScopedID(source profileSource, id string) string {
|
||||
}
|
||||
|
||||
func makeProfileKey(source profileSource, id string) string {
|
||||
return profilesDBPath + string(source) + "/" + id
|
||||
return ProfilesDBPath + string(source) + "/" + id
|
||||
}
|
||||
|
||||
func registerValidationDBHook() (err error) {
|
||||
_, err = database.RegisterHook(query.New(profilesDBPath), &databaseHook{})
|
||||
_, err = database.RegisterHook(query.New(ProfilesDBPath), &databaseHook{})
|
||||
return
|
||||
}
|
||||
|
||||
func startProfileUpdateChecker() error {
|
||||
module.StartServiceWorker("update active profiles", 0, func(ctx context.Context) (err error) {
|
||||
profilesSub, err := profileDB.Subscribe(query.New(profilesDBPath))
|
||||
profilesSub, err := profileDB.Subscribe(query.New(ProfilesDBPath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -59,7 +59,7 @@ func startProfileUpdateChecker() error {
|
||||
}
|
||||
|
||||
// Get active profile.
|
||||
activeProfile := getActiveProfile(strings.TrimPrefix(r.Key(), profilesDBPath))
|
||||
activeProfile := getActiveProfile(strings.TrimPrefix(r.Key(), ProfilesDBPath))
|
||||
if activeProfile == nil {
|
||||
// Don't do any additional actions if the profile is not active.
|
||||
continue profileFeed
|
||||
|
||||
@@ -177,7 +177,7 @@ func GetLocalProfile(id string, md MatchingData, createProfileCallback func() *P
|
||||
// getProfile fetches the profile for the given scoped ID.
|
||||
func getProfile(scopedID string) (profile *Profile, err error) {
|
||||
// Get profile from the database.
|
||||
r, err := profileDB.Get(profilesDBPath + scopedID)
|
||||
r, err := profileDB.Get(ProfilesDBPath + scopedID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -193,7 +193,7 @@ func findProfile(source profileSource, md MatchingData) (profile *Profile, err e
|
||||
// process might be quite expensive. Measure impact and possibly improve.
|
||||
|
||||
// Get iterator over all profiles.
|
||||
it, err := profileDB.Query(query.New(profilesDBPath + makeScopedID(source, "")))
|
||||
it, err := profileDB.Query(query.New(ProfilesDBPath + makeScopedID(source, "")))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query for profiles: %w", err)
|
||||
}
|
||||
@@ -299,7 +299,7 @@ func notifyConflictingProfiles(a, b record.Record, md MatchingData) {
|
||||
idA = profileA.ScopedID()
|
||||
nameA = profileA.Name
|
||||
} else {
|
||||
idA = strings.TrimPrefix(a.Key(), profilesDBPath)
|
||||
idA = strings.TrimPrefix(a.Key(), ProfilesDBPath)
|
||||
nameA = path.Base(idA)
|
||||
}
|
||||
profileB, err := EnsureProfile(b)
|
||||
@@ -307,7 +307,7 @@ func notifyConflictingProfiles(a, b record.Record, md MatchingData) {
|
||||
idB = profileB.ScopedID()
|
||||
nameB = profileB.Name
|
||||
} else {
|
||||
idB = strings.TrimPrefix(b.Key(), profilesDBPath)
|
||||
idB = strings.TrimPrefix(b.Key(), ProfilesDBPath)
|
||||
nameB = path.Base(idB)
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ func migrateNetworkRatingSystem(ctx context.Context, _, to *version.Version, db
|
||||
|
||||
func migrateLinkedPath(ctx context.Context, _, to *version.Version, db *database.Interface) error {
|
||||
// Get iterator over all profiles.
|
||||
it, err := db.Query(query.New(profilesDBPath))
|
||||
it, err := db.Query(query.New(ProfilesDBPath))
|
||||
if err != nil {
|
||||
log.Tracer(ctx).Errorf("profile: failed to migrate from linked path: failed to start query: %s", err)
|
||||
return nil
|
||||
@@ -112,7 +112,7 @@ func migrateLinkedPath(ctx context.Context, _, to *version.Version, db *database
|
||||
|
||||
func migrateIcons(ctx context.Context, _, to *version.Version, db *database.Interface) error {
|
||||
// Get iterator over all profiles.
|
||||
it, err := db.Query(query.New(profilesDBPath))
|
||||
it, err := db.Query(query.New(ProfilesDBPath))
|
||||
if err != nil {
|
||||
log.Tracer(ctx).Errorf("profile: failed to migrate from icon fields: failed to start query: %s", err)
|
||||
return nil
|
||||
@@ -181,7 +181,7 @@ func migrateToDerivedIDs(ctx context.Context, _, to *version.Version, db *databa
|
||||
var profilesToDelete []string //nolint:prealloc // We don't know how many profiles there are.
|
||||
|
||||
// Get iterator over all profiles.
|
||||
it, err := db.Query(query.New(profilesDBPath))
|
||||
it, err := db.Query(query.New(ProfilesDBPath))
|
||||
if err != nil {
|
||||
log.Tracer(ctx).Errorf("profile: failed to migrate to derived profile IDs: failed to start query: %s", err)
|
||||
return nil
|
||||
@@ -243,7 +243,7 @@ func migrateToDerivedIDs(ctx context.Context, _, to *version.Version, db *databa
|
||||
|
||||
// Delete old migrated profiles.
|
||||
for _, scopedID := range profilesToDelete {
|
||||
if err := db.Delete(profilesDBPath + scopedID); err != nil {
|
||||
if err := db.Delete(ProfilesDBPath + scopedID); err != nil {
|
||||
log.Tracer(ctx).Errorf("profile: failed to delete old profile %s during migration: %s", scopedID, err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user