Skip to content

Commit

Permalink
Use server request caching
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Jan 12, 2024
1 parent bcbc900 commit 558545c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 48 deletions.
4 changes: 4 additions & 0 deletions Fyreplace.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
4D1984D12891ACAC0074045F /* BaseListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D1984D02891ACAC0074045F /* BaseListViewController.swift */; };
4D1984D32891CC290074045F /* FPComment+Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D1984D22891CC290074045F /* FPComment+Notification.swift */; };
4D1F07CA28BA545A0074B158 /* BaseLister.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D1F07C928BA545A0074B158 /* BaseLister.swift */; };
4D2572612B517D050049C143 /* RequestIdentificationInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D2572602B517D050049C143 /* RequestIdentificationInterceptor.swift */; };
4D28B2DA28C7268D007D09C1 /* FPNotification+IdentifiableItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D28B2D928C7268D007D09C1 /* FPNotification+IdentifiableItem.swift */; };
4D41605928797FF0008584FC /* CommentActivityItemProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D41605828797FEF008584FC /* CommentActivityItemProvider.swift */; };
4D45C0A128A7F31800B946E8 /* NotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4D45C0A028A7F31800B946E8 /* NotificationTableViewCell.swift */; };
Expand Down Expand Up @@ -207,6 +208,7 @@
4D22461B279C284300D35430 /* FPUserServiceNIOClient+ItemListerService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FPUserServiceNIOClient+ItemListerService.swift"; sourceTree = "<group>"; };
4D22461D279CBAA500D35430 /* BlockedUserTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockedUserTableViewCell.swift; sourceTree = "<group>"; };
4D22461F279CBBD800D35430 /* AvatarTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AvatarTableViewCell.swift; sourceTree = "<group>"; };
4D2572602B517D050049C143 /* RequestIdentificationInterceptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestIdentificationInterceptor.swift; sourceTree = "<group>"; };
4D28876126A74F7200D6D3CB /* Rpc.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Rpc.swift; sourceTree = "<group>"; };
4D28B2D928C7268D007D09C1 /* FPNotification+IdentifiableItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FPNotification+IdentifiableItem.swift"; sourceTree = "<group>"; };
4D350CEF27235A6E00D40BE2 /* PostViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -496,6 +498,7 @@
4D1F07C928BA545A0074B158 /* BaseLister.swift */,
4D1FF61027085F9600445793 /* ItemLister.swift */,
4DC88FA027B4550E00F06921 /* ItemRandomAccessLister.swift */,
4D2572602B517D050049C143 /* RequestIdentificationInterceptor.swift */,
4DC05C1D2B48676F00C07F4E /* AuthenticationInterceptor.swift */,
4DC05C1F2B486E6200C07F4E /* ServiceClientInterceptors.swift */,
);
Expand Down Expand Up @@ -807,6 +810,7 @@
4D77942927DE654B0068F4E7 /* CompactTextView.swift in Sources */,
4D020222285E5A5800D85B79 /* FPPost+Notification.swift in Sources */,
4D77942A27DE654B0068F4E7 /* ItemListViewController.swift in Sources */,
4D2572612B517D050049C143 /* RequestIdentificationInterceptor.swift in Sources */,
4D862789284B6D4D00A9320D /* URLActivityItemProvider.swift in Sources */,
4D77942B27DE654B0068F4E7 /* Array+IndexPath.swift in Sources */,
4D77942C27DE654B0068F4E7 /* String.swift in Sources */,
Expand Down
14 changes: 14 additions & 0 deletions Fyreplace/Sources/gRPC/RequestIdentificationInterceptor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation
import GRPC
import NIOCore

class RequestIdentificationInterceptor<Request, Response>: ClientInterceptor<Request, Response> {
override func send(_ part: GRPCClientRequestPart<Request>, promise: EventLoopPromise<Void>?, context: ClientInterceptorContext<Request, Response>) {
if case var GRPCClientRequestPart.metadata(headers) = part {
headers.add(name: "x-request-id", value: UUID().uuidString)
super.send(.metadata(headers), promise: promise, context: context)
} else {
super.send(part, promise: promise, context: context)
}
}
}
100 changes: 52 additions & 48 deletions Fyreplace/Sources/gRPC/ServiceClientInterceptors.swift
Original file line number Diff line number Diff line change
@@ -1,206 +1,210 @@
import GRPC
import SwiftProtobuf

func makeInterceptors<Request, Response>() -> [ClientInterceptor<Request, Response>] {
return [RequestIdentificationInterceptor(), AuthenticationInterceptor()]
}

struct AccountServiceClientInterceptorFactory: FPAccountServiceClientInterceptorFactoryProtocol {
func makeCreateInterceptors() -> [ClientInterceptor<FPUserCreation, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPUserCreation, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeDeleteInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeSendActivationEmailInterceptors() -> [ClientInterceptor<FPEmail, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPEmail, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeConfirmActivationInterceptors() -> [ClientInterceptor<FPConnectionToken, FPToken>] {
return [AuthenticationInterceptor<FPConnectionToken, FPToken>()]
return makeInterceptors()
}

func makeListConnectionsInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, FPConnections>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, FPConnections>()]
return makeInterceptors()
}

func makeSendConnectionEmailInterceptors() -> [ClientInterceptor<FPEmail, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPEmail, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeConfirmConnectionInterceptors() -> [ClientInterceptor<FPConnectionToken, FPToken>] {
return [AuthenticationInterceptor<FPConnectionToken, FPToken>()]
return makeInterceptors()
}

func makeConnectInterceptors() -> [ClientInterceptor<FPConnectionCredentials, FPToken>] {
return [AuthenticationInterceptor<FPConnectionCredentials, FPToken>()]
return makeInterceptors()
}

func makeDisconnectInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeDisconnectAllInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, Google_Protobuf_Empty>()]
return makeInterceptors()
}
}

struct UserServiceClientInterceptorFactory: FPUserServiceClientInterceptorFactoryProtocol {
func makeRetrieveInterceptors() -> [ClientInterceptor<FPId, FPUser>] {
return [AuthenticationInterceptor<FPId, FPUser>()]
return makeInterceptors()
}

func makeRetrieveMeInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, FPUser>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, FPUser>()]
return makeInterceptors()
}

func makeUpdateAvatarInterceptors() -> [ClientInterceptor<FPImageChunk, FPImage>] {
return [AuthenticationInterceptor<FPImageChunk, FPImage>()]
return makeInterceptors()
}

func makeUpdateBioInterceptors() -> [ClientInterceptor<FPBio, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPBio, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeSendEmailUpdateEmailInterceptors() -> [ClientInterceptor<FPEmail, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPEmail, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeConfirmEmailUpdateInterceptors() -> [ClientInterceptor<FPToken, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPToken, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeListBlockedInterceptors() -> [ClientInterceptor<FPPage, FPProfiles>] {
return [AuthenticationInterceptor<FPPage, FPProfiles>()]
return makeInterceptors()
}

func makeUpdateBlockInterceptors() -> [ClientInterceptor<FPBlock, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPBlock, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeReportInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeAbsolveInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeBanInterceptors() -> [ClientInterceptor<FPBanSentence, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPBanSentence, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makePromoteInterceptors() -> [ClientInterceptor<FPPromotion, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPPromotion, Google_Protobuf_Empty>()]
return makeInterceptors()
}
}

struct PostServiceClientInterceptorFactory: FPPostServiceClientInterceptorFactoryProtocol {
func makeListFeedInterceptors() -> [ClientInterceptor<FPVote, FPPost>] {
return [AuthenticationInterceptor<FPVote, FPPost>()]
return makeInterceptors()
}

func makeListArchiveInterceptors() -> [ClientInterceptor<FPPage, FPPosts>] {
return [AuthenticationInterceptor<FPPage, FPPosts>()]
return makeInterceptors()
}

func makeListOwnPostsInterceptors() -> [ClientInterceptor<FPPage, FPPosts>] {
return [AuthenticationInterceptor<FPPage, FPPosts>()]
return makeInterceptors()
}

func makeListDraftsInterceptors() -> [ClientInterceptor<FPPage, FPPosts>] {
return [AuthenticationInterceptor<FPPage, FPPosts>()]
return makeInterceptors()
}

func makeRetrieveInterceptors() -> [ClientInterceptor<FPId, FPPost>] {
return [AuthenticationInterceptor<FPId, FPPost>()]
return makeInterceptors()
}

func makeCreateInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, FPId>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, FPId>()]
return makeInterceptors()
}

func makePublishInterceptors() -> [ClientInterceptor<FPPublication, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPPublication, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeDeleteInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeUpdateSubscriptionInterceptors() -> [ClientInterceptor<FPSubscription, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPSubscription, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeReportInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeAbsolveInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}
}

struct ChapterServiceClientInterceptorFactory: FPChapterServiceClientInterceptorFactoryProtocol {
func makeCreateInterceptors() -> [ClientInterceptor<FPChapterLocation, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPChapterLocation, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeMoveInterceptors() -> [ClientInterceptor<FPChapterRelocation, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPChapterRelocation, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeUpdateTextInterceptors() -> [ClientInterceptor<FPChapterTextUpdate, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPChapterTextUpdate, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeUpdateImageInterceptors() -> [ClientInterceptor<FPChapterImageUpdate, FPImage>] {
return [AuthenticationInterceptor<FPChapterImageUpdate, FPImage>()]
return makeInterceptors()
}

func makeDeleteInterceptors() -> [ClientInterceptor<FPChapterLocation, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPChapterLocation, Google_Protobuf_Empty>()]
return makeInterceptors()
}
}

struct CommentServiceClientInterceptorFactory: FPCommentServiceClientInterceptorFactoryProtocol {
func makeListInterceptors() -> [ClientInterceptor<FPPage, FPComments>] {
return [AuthenticationInterceptor<FPPage, FPComments>()]
return makeInterceptors()
}

func makeCreateInterceptors() -> [ClientInterceptor<FPCommentCreation, FPId>] {
return [AuthenticationInterceptor<FPCommentCreation, FPId>()]
return makeInterceptors()
}

func makeDeleteInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeAcknowledgeInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeReportInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeAbsolveInterceptors() -> [ClientInterceptor<FPId, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPId, Google_Protobuf_Empty>()]
return makeInterceptors()
}
}

struct NotificationServiceClientInterceptorFactory: FPNotificationServiceClientInterceptorFactoryProtocol {
func makeCountInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, FPNotificationCount>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, FPNotificationCount>()]
return makeInterceptors()
}

func makeListInterceptors() -> [ClientInterceptor<FPPage, FPNotifications>] {
return [AuthenticationInterceptor<FPPage, FPNotifications>()]
return makeInterceptors()
}

func makeClearInterceptors() -> [ClientInterceptor<Google_Protobuf_Empty, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<Google_Protobuf_Empty, Google_Protobuf_Empty>()]
return makeInterceptors()
}

func makeRegisterTokenInterceptors() -> [ClientInterceptor<FPMessagingToken, Google_Protobuf_Empty>] {
return [AuthenticationInterceptor<FPMessagingToken, Google_Protobuf_Empty>()]
return makeInterceptors()
}
}

0 comments on commit 558545c

Please sign in to comment.