Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Drop in-memory cache
Browse files Browse the repository at this point in the history
  • Loading branch information
bfollington committed Oct 11, 2023
1 parent 3096071 commit 3080e5d
Showing 1 changed file with 1 addition and 32 deletions.
33 changes: 1 addition & 32 deletions xcode/Subconscious/Shared/Services/UserProfileService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@ struct UserProfileEntry: Codable, Equatable {
let bio: String?
}

struct UserProfileCacheEntry {
let profile: UserProfile
let version: Cid
}

struct UserProfileCacheKey: Hashable {
let did: Did
let petname: Petname?
}

actor UserProfileService {
private var noosphere: NoosphereService
private var database: DatabaseService
Expand All @@ -131,8 +121,6 @@ actor UserProfileService {

private static let profileContentType = "application/vnd.subconscious.profile+json"

private var cache: [UserProfileCacheKey:UserProfileCacheEntry] = [:]

init(
noosphere: NoosphereService,
database: DatabaseService,
Expand Down Expand Up @@ -410,24 +398,10 @@ actor UserProfileService {
petname: Petname?,
context: Peer?
) async throws -> UserProfile {
let version = try await self.noosphere.version()

// Check cache
let cacheKey = UserProfileCacheKey(did: did, petname: petname)
if let cacheHit = self.cache[cacheKey],
cacheHit.version == version {
return cacheHit.profile
}

// Special case: our profile
let identity = try await self.noosphere.identity()
guard did != identity else {
let profile = try await readOurProfile(alias: petname)
self.cache.updateValue(
UserProfileCacheEntry(profile: profile, version: version),
forKey: cacheKey
)
return profile
return try await readOurProfile(alias: petname)
}

let following = await self.addressBook.followingStatus(
Expand Down Expand Up @@ -495,11 +469,6 @@ actor UserProfileService {
return sparseProfile
}
}

self.cache.updateValue(
UserProfileCacheEntry(profile: profile, version: version),
forKey: cacheKey
)

return profile
}
Expand Down

0 comments on commit 3080e5d

Please sign in to comment.