Skip to content

Commit

Permalink
Feat: sort by count and appName
Browse files Browse the repository at this point in the history
  • Loading branch information
Butanediol committed Mar 14, 2022
1 parent 73ea9a9 commit 4d4d1e7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Release build

on:
push:
tags:
- 'v*.*.*'
branches: [ main ]
pull_request:
branches: [ main ]
Expand Down Expand Up @@ -35,5 +37,6 @@ jobs:

- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: .build/x86_64-unknown-linux-gnu/release/Run
30 changes: 17 additions & 13 deletions Sources/App/Controllers/AppInfoController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ struct AppInfoController: RouteCollection {
let appInfo = try req.content.decode(AppInfo.self)
appInfo.count = 1
appInfo.id = UUID()
appInfo.signature = appInfo.signature == "app-tracker" ? "" : appInfo.signature
return appInfo
}()

let withSignature = newAppInfo.signature != "" && newAppInfo.signature != "app-tracker"
let withSignature = newAppInfo.signature != ""

// Update appName of all app with the same packageName and activityName
try await AppInfo.query(on: req.db)
.filter(\.$packageName == newAppInfo.packageName)
.filter(\.$activityName == newAppInfo.activityName)
Expand All @@ -73,24 +75,25 @@ struct AppInfoController: RouteCollection {
}
.end()

if withSignature {
if let old = try await AppInfo.query(on: req.db)
.filter(\.$packageName == newAppInfo.packageName)
.filter(\.$activityName == newAppInfo.activityName)
.filter(\.$signature == newAppInfo.signature)
.first() {
old.count! += 1
try await old.update(on: req.db)
} else {
try await newAppInfo.create(on: req.db)
}
if let old = try await AppInfo.query(on: req.db)
.filter(\.$packageName == newAppInfo.packageName)
.filter(\.$activityName == newAppInfo.activityName)
.filter(\.$signature == newAppInfo.signature)
.first() {
// If already exists, counter ++
old.count! += 1
try await old.update(on: req.db)
} else {
// If not, create new
try await newAppInfo.create(on: req.db)
}

if try await AppInfo.query(on: req.db)
.filter(\.$packageName == newAppInfo.packageName)
.filter(\.$activityName == newAppInfo.activityName)
.filter(\.$signature == "")
.first() == nil {
.first() == nil, withSignature {
// If the new has signature, also havent been recorded, erase signature then copy.
try await newAppInfo.eraseSignature().create(on: req.db)
}

Expand Down Expand Up @@ -127,6 +130,7 @@ struct AppInfoController: RouteCollection {
}
}
}
.sort(\.$count, .descending)
.sort(\.$appName, .ascending)
.paginate(for: req)
}
Expand Down

0 comments on commit 4d4d1e7

Please sign in to comment.