Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native set load measured #8242

Merged
merged 5 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/managers/performance_metrics_manager/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import RNUtils from '@mattermost/rnutils';
import {AppState, type AppStateStatus} from 'react-native';
import performance from 'react-native-performance';

Expand All @@ -18,7 +19,6 @@ const MAX_RETRIES = 3;
class PerformanceMetricsManager {
private target: Target;
private batchers: {[serverUrl: string]: Batcher} = {};
private hasRegisteredLoad = false;
private lastAppStateIsActive = AppState.currentState === 'active';

constructor() {
Expand Down Expand Up @@ -49,15 +49,15 @@ class PerformanceMetricsManager {
}

public skipLoadMetric() {
this.hasRegisteredLoad = true;
RNUtils.setHasRegisteredLoad();
}

public finishLoad(location: Target, serverUrl: string) {
this.finishLoadWithRetries(location, serverUrl, 0);
}

private finishLoadWithRetries(location: Target, serverUrl: string, retries: number) {
if (this.target !== location || this.hasRegisteredLoad) {
if (this.target !== location || RNUtils.getHasRegisteredLoad().hasRegisteredLoad) {
return;
}

Expand All @@ -79,7 +79,7 @@ class PerformanceMetricsManager {
logWarning('We could not retrieve the mobile load metric');
}

this.hasRegisteredLoad = true;
RNUtils.setHasRegisteredLoad();
}

public startMetric(metricName: MetricName) {
Expand Down
46 changes: 23 additions & 23 deletions ios/Gekidou/Sources/Gekidou/Storage/Database+Category.swift
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in this package are because of changes in iOS 18.

Copy link
Contributor

@enahum enahum Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a better solution for this.. I'll share when I can.

Btw this is cause Xcode 16 not ios 18

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The better way to fix this issue is by adding this line typealias Expression = SQLite.Expression after the imports in the Storage/Database.swift file, all other changes to the Gekidou library would not be needed.

Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import SQLite
extension Database {
public func queryCategoryId(inTeamId teamId: String, type: String, forServerUrl serverUrl: String) -> String? {
if let db = try? getDatabaseForServer(serverUrl) {
let idCol = Expression<String>("id")
let teamIdCol = Expression<String>("team_id")
let typeCol = Expression<String>("type")
let idCol = SQLite.Expression<String>("id")
Copy link
Contributor

@rahimrahman rahimrahman Oct 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these changes because of Xcode 16? If they are Since this changes are caused by Xcode 16 unrelated to the problem, would it have been better to handle those in a separate PR beforehand. It would help keep the focus on the main bug fix here.

Updated: since I read previous comment that the problem is due to Xcode 16.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I admit, when I saw 23 files changed, I made a note to myself that I need to carve a bit more time to run through this PR.

let teamIdCol = SQLite.Expression<String>("team_id")
let typeCol = SQLite.Expression<String>("type")
let query = categoryTable.where(teamIdCol == teamId && typeCol == type)
if let result = try? db.pluck(query) {
return try? result.get(idCol)
Expand All @@ -18,9 +18,9 @@ extension Database {

public func queryCategoryChannelId(inCategoryId categoryId: String, channelId: String, forServerUrl serverUrl: String) -> String? {
if let db = try? getDatabaseForServer(serverUrl) {
let idCol = Expression<String>("id")
let categoryIdCol = Expression<String>("category_id")
let channelIdCol = Expression<String>("channel_id")
let idCol = SQLite.Expression<String>("id")
let categoryIdCol = SQLite.Expression<String>("category_id")
let channelIdCol = SQLite.Expression<String>("channel_id")
let query = categoryChannelTable.where(categoryIdCol == categoryId && channelIdCol == channelId)
if let result = try? db.pluck(query) {
return try? result.get(idCol)
Expand All @@ -38,7 +38,7 @@ extension Database {
}

public func insertChannelToDefaultCategory(_ db: Connection, _ categoryChannels: [CategoryChannel]) throws {
let categoryId = Expression<String>("category_id")
let categoryId = SQLite.Expression<String>("category_id")
for cc in categoryChannels {
let count = (try? db.scalar(categoryChannelTable.where(categoryId == cc.categoryId).count)) ?? 0
let setter = createCategoryChannelsSetter(from: cc, index: count > 0 ? count + 1 : 0)
Expand All @@ -47,14 +47,14 @@ extension Database {
}

private func createCategoriesSetter(from categories: [Category]) -> [[Setter]] {
let id = Expression<String>("id")
let collapsed = Expression<Bool>("collapsed")
let displayName = Expression<String>("display_name")
let muted = Expression<Bool>("muted")
let sortOrder = Expression<Int>("sort_order")
let sorting = Expression<String>("sorting")
let teamId = Expression<String>("team_id")
let type = Expression<String>("type")
let id = SQLite.Expression<String>("id")
let collapsed = SQLite.Expression<Bool>("collapsed")
let displayName = SQLite.Expression<String>("display_name")
let muted = SQLite.Expression<Bool>("muted")
let sortOrder = SQLite.Expression<Int>("sort_order")
let sorting = SQLite.Expression<String>("sorting")
let teamId = SQLite.Expression<String>("team_id")
let type = SQLite.Expression<String>("type")

var setters = [[Setter]]()
for category in categories {
Expand All @@ -74,10 +74,10 @@ extension Database {
}

private func createCategoryChannelsSetter(from categories: [Category]) -> [[Setter]] {
let id = Expression<String>("id")
let categoryId = Expression<String>("category_id")
let channelId = Expression<String>("channel_id")
let sortOrder = Expression<Int>("sort_order")
let id = SQLite.Expression<String>("id")
let categoryId = SQLite.Expression<String>("category_id")
let channelId = SQLite.Expression<String>("channel_id")
let sortOrder = SQLite.Expression<Int>("sort_order")

var setters = [[Setter]]()
for category in categories {
Expand All @@ -95,10 +95,10 @@ extension Database {
}

private func createCategoryChannelsSetter(from categoryChannel: CategoryChannel, index: Int = 0) -> [Setter] {
let id = Expression<String>("id")
let categoryId = Expression<String>("category_id")
let channelId = Expression<String>("channel_id")
let sortOrder = Expression<Int>("sort_order")
let id = SQLite.Expression<String>("id")
let categoryId = SQLite.Expression<String>("category_id")
let channelId = SQLite.Expression<String>("channel_id")
let sortOrder = SQLite.Expression<Int>("sort_order")

var setter = [Setter]()
setter.append(id <- categoryChannel.id)
Expand Down
74 changes: 37 additions & 37 deletions ios/Gekidou/Sources/Gekidou/Storage/Database+Channels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ extension Database {
internal func queryCurrentChannelId(_ serverUrl: String) throws -> String {
let db = try getDatabaseForServer(serverUrl)

let idCol = Expression<String>("id")
let valueCol = Expression<String>("value")
let idCol = SQLite.Expression<String>("id")
let valueCol = SQLite.Expression<String>("value")
let query = systemTable.where(idCol == "currentChannelId")

if let result = try db.pluck(query) {
Expand Down Expand Up @@ -42,7 +42,7 @@ extension Database {

public func queryChannelExists(withId channelId: String, forServerUrl serverUrl: String) -> Bool {
if let db = try? getDatabaseForServer(serverUrl) {
let idCol = Expression<String>("id")
let idCol = SQLite.Expression<String>("id")
let query = channelTable.where(idCol == channelId)
if let _ = try? db.pluck(query) {
return true
Expand All @@ -52,7 +52,7 @@ extension Database {
}

public func hasMyChannel(_ db: Connection, channelId: String) -> Bool {
let idCol = Expression<String>("id")
let idCol = SQLite.Expression<String>("id")
let query = myChannelTable.where(idCol == channelId)
if let _ = try? db.pluck(query) {
return true
Expand Down Expand Up @@ -216,12 +216,12 @@ extension Database {
}

public func insertOrUpdateMyChannel(_ db: Connection, _ myChannel: ChannelMember, _ isCRTEnabled: Bool, _ lastFetchedAt: Double, _ lastPostAt: Double) throws {
let idCol = Expression<String>("id")
let messageCountCol = Expression<Int>("message_count")
let mentionsCol = Expression<Int>("mentions_count")
let isUnreadCol = Expression<Bool>("is_unread")
let lastFetchedAtCol = Expression<Double>("last_fetched_at")
let lastPostAtCol = Expression<Double>("last_post_at")
let idCol = SQLite.Expression<String>("id")
let messageCountCol = SQLite.Expression<Int>("message_count")
let mentionsCol = SQLite.Expression<Int>("mentions_count")
let isUnreadCol = SQLite.Expression<Bool>("is_unread")
let lastFetchedAtCol = SQLite.Expression<Double>("last_fetched_at")
let lastPostAtCol = SQLite.Expression<Double>("last_post_at")
let mentionsCount = isCRTEnabled ? myChannel.mentionCountRoot : myChannel.mentionCount
let messageCount = isCRTEnabled ? myChannel.internalMsgCountRoot : myChannel.internalMsgCount
let isUnread = messageCount > 0
Expand All @@ -237,10 +237,10 @@ extension Database {
)
let _ = try db.run(updateQuery)
} else {
let rolesCol = Expression<String>("roles")
let manuallyUnreadCol = Expression<Bool>("manually_unread")
let lastViewedAtCol = Expression<Double>("last_viewed_at")
let viewedAtCol = Expression<Double>("viewed_at")
let rolesCol = SQLite.Expression<String>("roles")
let manuallyUnreadCol = SQLite.Expression<Bool>("manually_unread")
let lastViewedAtCol = SQLite.Expression<Double>("last_viewed_at")
let viewedAtCol = SQLite.Expression<Double>("viewed_at")

let setter: [Setter] = [
idCol <- myChannel.id,
Expand All @@ -261,8 +261,8 @@ extension Database {
}

private func insertMyChannelSettings(_ db: Connection, _ myChannel: ChannelMember) throws {
let id = Expression<String>("id")
let notifyProps = Expression<String>("notify_props")
let id = SQLite.Expression<String>("id")
let notifyProps = SQLite.Expression<String>("notify_props")

let setter: [Setter] = [
id <- myChannel.id,
Expand All @@ -273,10 +273,10 @@ extension Database {
}

private func insertChannelMember(_ db: Connection, _ member: ChannelMember) throws {
let id = Expression<String>("id")
let channelId = Expression<String>("channel_id")
let userId = Expression<String>("user_id")
let schemeAdmin = Expression<Bool>("scheme_admin")
let id = SQLite.Expression<String>("id")
let channelId = SQLite.Expression<String>("channel_id")
let userId = SQLite.Expression<String>("user_id")
let schemeAdmin = SQLite.Expression<Bool>("scheme_admin")

let setter: [Setter] = [
id <- "\(member.id)-\(member.userId)",
Expand All @@ -289,17 +289,17 @@ extension Database {
}

private func createChannelSetter(from channel: Channel) -> [Setter] {
let id = Expression<String>("id")
let createAt = Expression<Double>("create_at")
let deleteAt = Expression<Double>("delete_at")
let updateAt = Expression<Double>("update_at")
let creatorId = Expression<String>("creator_id")
let displayName = Expression<String>("display_name")
let name = Expression<String>("name")
let teamId = Expression<String>("team_id")
let type = Expression<String>("type")
let isGroupConstrained = Expression<Bool>("group_constrained")
let shared = Expression<Bool>("shared")
let id = SQLite.Expression<String>("id")
let createAt = SQLite.Expression<Double>("create_at")
let deleteAt = SQLite.Expression<Double>("delete_at")
let updateAt = SQLite.Expression<Double>("update_at")
let creatorId = SQLite.Expression<String>("creator_id")
let displayName = SQLite.Expression<String>("display_name")
let name = SQLite.Expression<String>("name")
let teamId = SQLite.Expression<String>("team_id")
let type = SQLite.Expression<String>("type")
let isGroupConstrained = SQLite.Expression<Bool>("group_constrained")
let shared = SQLite.Expression<Bool>("shared")

var setter = [Setter]()
setter.append(id <- channel.id)
Expand All @@ -318,12 +318,12 @@ extension Database {
}

private func createChannelInfoSetter(from channel: Channel) -> [Setter] {
let id = Expression<String>("id")
let header = Expression<String>("header")
let purpose = Expression<String>("purpose")
let guestCount = Expression<Int>("guest_count")
let memberCount = Expression<Int>("member_count")
let pinnedPostCount = Expression<Int>("pinned_post_count")
let id = SQLite.Expression<String>("id")
let header = SQLite.Expression<String>("header")
let purpose = SQLite.Expression<String>("purpose")
let guestCount = SQLite.Expression<Int>("guest_count")
let memberCount = SQLite.Expression<Int>("member_count")
let pinnedPostCount = SQLite.Expression<Int>("pinned_post_count")

var setter = [Setter]()
setter.append(id <- channel.id)
Expand Down
14 changes: 7 additions & 7 deletions ios/Gekidou/Sources/Gekidou/Storage/Database+Mentions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ extension Database {

public func resetMyChannelMentions(_ serverUrl: String, _ channelId: String) throws {
if let db = try? getDatabaseForServer(serverUrl) {
let idCol = Expression<String>("id")
let mentionsCol = Expression<Int>("mentions_count")
let msgCol = Expression<Int>("message_count")
let isUnreadCol = Expression<Bool>("is_unread")
let idCol = SQLite.Expression<String>("id")
let mentionsCol = SQLite.Expression<Int>("mentions_count")
let msgCol = SQLite.Expression<Int>("message_count")
let isUnreadCol = SQLite.Expression<Bool>("is_unread")
if hasMyChannel(db, channelId: channelId) {
let updateQuery = myChannelTable
.where(idCol == channelId)
Expand All @@ -59,9 +59,9 @@ extension Database {

public func resetThreadMentions(_ serverUrl: String, _ rootId: String) throws {
if let db = try? getDatabaseForServer(serverUrl) {
let idCol = Expression<String>("id")
let mentionsCol = Expression<Int>("unread_mentions")
let msgCol = Expression<Int>("unread_replies")
let idCol = SQLite.Expression<String>("id")
let mentionsCol = SQLite.Expression<Int>("unread_mentions")
let msgCol = SQLite.Expression<Int>("unread_replies")
if hasThread(db, threadId: rootId) {
let updateQuery = threadTable
.where(idCol == rootId)
Expand Down
Loading
Loading