Merge pull request #584 from mpretty-cyro/feature/cache-public-key-retrieval

Performance: Cache public key retrieval
This commit is contained in:
RyanZhao 2022-03-21 13:56:39 +11:00 committed by GitHub
commit 05352daecb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 37 deletions

View File

@ -241,8 +241,6 @@
B894D0752339EDCF00B4D94D /* NukeDataModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B894D0742339EDCF00B4D94D /* NukeDataModal.swift */; };
B897621C25D201F7004F83B2 /* ScrollToBottomButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = B897621B25D201F7004F83B2 /* ScrollToBottomButton.swift */; };
B8AE75A425A6C6A6001A84D2 /* Data+Trimming.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */; };
B8AE760B25ABFB5A001A84D2 /* GeneralUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = B8AE760A25ABFB5A001A84D2 /* GeneralUtilities.m */; };
B8AE761425ABFBB9001A84D2 /* GeneralUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = B8AE760925ABFB00001A84D2 /* GeneralUtilities.h */; settings = {ATTRIBUTES = (Public, ); }; };
B8AF4BB426A5204600583500 /* SendSeedModal.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8AF4BB326A5204600583500 /* SendSeedModal.swift */; };
B8B32021258B1A650020074B /* Contact.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B32020258B1A650020074B /* Contact.swift */; };
B8B32033258B235D0020074B /* Storage+Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8B32032258B235D0020074B /* Storage+Contacts.swift */; };
@ -1249,8 +1247,6 @@
B894D0742339EDCF00B4D94D /* NukeDataModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NukeDataModal.swift; sourceTree = "<group>"; };
B897621B25D201F7004F83B2 /* ScrollToBottomButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollToBottomButton.swift; sourceTree = "<group>"; };
B8AE75A325A6C6A6001A84D2 /* Data+Trimming.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Trimming.swift"; sourceTree = "<group>"; };
B8AE760925ABFB00001A84D2 /* GeneralUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneralUtilities.h; sourceTree = "<group>"; };
B8AE760A25ABFB5A001A84D2 /* GeneralUtilities.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = GeneralUtilities.m; sourceTree = "<group>"; };
B8AF4BB326A5204600583500 /* SendSeedModal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendSeedModal.swift; sourceTree = "<group>"; };
B8B32020258B1A650020074B /* Contact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contact.swift; sourceTree = "<group>"; };
B8B32032258B235D0020074B /* Storage+Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Storage+Contacts.swift"; sourceTree = "<group>"; };
@ -3225,8 +3221,6 @@
C3BBE0C62554F1570050F1E3 /* FixedWidthInteger+BigEndian.swift */,
C33FDB7F255A581100E217F9 /* FullTextSearchFinder.swift */,
C33FDBC1255A581700E217F9 /* General.swift */,
B8AE760925ABFB00001A84D2 /* GeneralUtilities.h */,
B8AE760A25ABFB5A001A84D2 /* GeneralUtilities.m */,
B82A0C3726B9098200C1BCE3 /* MessageInvalidator.swift */,
C3A71D0A2558989C0043A11F /* MessageWrapper.swift */,
C3A71D4E25589FF30043A11F /* NSData+messagePadding.h */,
@ -3789,7 +3783,6 @@
C32C5BF8256DC8F6003C73A2 /* OWSDisappearingMessagesJob.h in Headers */,
C32C5AAA256DBE8F003C73A2 /* TSIncomingMessage.h in Headers */,
B8856D72256F1421001CE70E /* OWSWindowManager.h in Headers */,
B8AE761425ABFBB9001A84D2 /* GeneralUtilities.h in Headers */,
C32C5B6B256DC357003C73A2 /* OWSDisappearingConfigurationUpdateInfoMessage.h in Headers */,
C32C5BBA256DC7E3003C73A2 /* ProfileManagerProtocol.h in Headers */,
C3A3A193256E20D4004D228D /* SignalRecipient.h in Headers */,
@ -4782,7 +4775,6 @@
C32C5E5B256DDF45003C73A2 /* OWSStorage.m in Sources */,
C32C5E15256DDC78003C73A2 /* SSKPreferences.swift in Sources */,
C32C5D9C256DD6DC003C73A2 /* OWSOutgoingReceiptManager.m in Sources */,
B8AE760B25ABFB5A001A84D2 /* GeneralUtilities.m in Sources */,
C32C5C4F256DCC36003C73A2 /* Storage+OpenGroups.swift in Sources */,
C3DA9C0725AE7396008F7C7E /* ConfigurationMessage.swift in Sources */,
B8856CEE256F1054001CE70E /* OWSAudioPlayer.m in Sources */,

View File

@ -1,4 +1,7 @@
import UIKit
import SessionUIKit
import SessionSnodeKit
import SessionMessagingKit
@objc(LKNukeDataModal)
final class NukeDataModal : Modal {
@ -125,6 +128,7 @@ final class NukeDataModal : Modal {
appDelegate.forceSyncConfigurationNowIfNeeded().ensure(on: DispatchQueue.main) {
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
General.Cache.cachedEncodedPublicKey = nil // Remove the cached key so it gets re-cached on next access
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
}.retainUntilComplete()
}
@ -136,6 +140,7 @@ final class NukeDataModal : Modal {
self?.dismiss(animated: true, completion: nil) // Dismiss the loader
let potentiallyMaliciousSnodes = confirmations.compactMap { $0.value == false ? $0.key : nil }
if potentiallyMaliciousSnodes.isEmpty {
General.Cache.cachedEncodedPublicKey = nil // Remove the cached key so it gets re-cached on next access
UserDefaults.removeAll() // Not done in the nuke data implementation as unlinking requires this to happen later
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
} else {

View File

@ -5,7 +5,6 @@ FOUNDATION_EXPORT const unsigned char SessionMessagingKitVersionString[];
#import <SessionMessagingKit/AppReadiness.h>
#import <SessionMessagingKit/Environment.h>
#import <SessionMessagingKit/GeneralUtilities.h>
#import <SessionMessagingKit/NotificationsProtocol.h>
#import <SessionMessagingKit/NSData+messagePadding.h>
#import <SessionMessagingKit/OWSAudioPlayer.h>

View File

@ -1,7 +1,25 @@
import Foundation
public enum General {
public enum Cache {
public static var cachedEncodedPublicKey: String? = nil
}
}
@objc(SNGeneralUtilities)
public class GeneralUtilities: NSObject {
@objc public static func getUserPublicKey() -> String {
return getUserHexEncodedPublicKey()
}
}
public func getUserHexEncodedPublicKey() -> String {
if let cachedKey: String = General.Cache.cachedEncodedPublicKey { return cachedKey }
if let keyPair = OWSIdentityManager.shared().identityKeyPair() { // Can be nil under some circumstances
General.Cache.cachedEncodedPublicKey = keyPair.hexEncodedPublicKey
return keyPair.hexEncodedPublicKey
}
return ""
}

View File

@ -1,11 +0,0 @@
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface SNGeneralUtilities : NSObject
+ (NSString *)getUserPublicKey;
@end
NS_ASSUME_NONNULL_END

View File

@ -1,16 +0,0 @@
#import <SessionUtilitiesKit/SessionUtilitiesKit.h>
#import "GeneralUtilities.h"
#import "OWSIdentityManager.h"
NS_ASSUME_NONNULL_BEGIN
@implementation SNGeneralUtilities
+ (NSString *)getUserPublicKey
{
return OWSIdentityManager.sharedManager.identityKeyPair.hexEncodedPublicKey;
}
@end
NS_ASSUME_NONNULL_END

View File

@ -28,7 +28,7 @@ public class NSENotificationPresenter: NSObject, NotificationsProtocol {
}
let senderPublicKey = incomingMessage.authorId
let userPublicKey = SNGeneralUtilities.getUserPublicKey()
let userPublicKey = GeneralUtilities.getUserPublicKey()
guard senderPublicKey != userPublicKey else {
// Ignore PNs for messages sent by the current user
// after handling the message. Otherwise the closed