mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 09:48:44 +00:00
refactor
This commit is contained in:
1 parent
620a4604b0
commit
87b4cfb3f2
4 files changed
+21
-11
No files matched your search
+1
-1
@@ -2,4 +2,4 @@
|
||||
-- noinspection SqlNoDataSourceInspectionForFile
|
||||
-- noinspection SqlResolveForFile
|
||||
|
||||
drop table analytics_active_users;
|
||||
drop table analytics_app_active_users;
|
||||
+4
-1
@@ -2,7 +2,7 @@
|
||||
-- noinspection SqlNoDataSourceInspectionForFile
|
||||
-- noinspection SqlResolveForFile
|
||||
|
||||
CREATE TABLE analytics_active_users (
|
||||
CREATE TABLE analytics_app_active_users (
|
||||
-- Not used for anything except replication.
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT,
|
||||
|
||||
@@ -13,6 +13,9 @@ CREATE TABLE analytics_active_users (
|
||||
-- Who sent the event.
|
||||
user_token VARCHAR(32) NOT NULL,
|
||||
|
||||
-- App version is updated on every write.
|
||||
app_version VARCHAR(32) NOT NULL,
|
||||
|
||||
-- IP address is updated on every write.
|
||||
ip_address VARCHAR(40) NOT NULL,
|
||||
|
||||
@@ -1 +1 @@
|
||||
mod upsert_analytics_active_user;
|
||||
mod upsert_analytics_app_active_user;
|
||||
+15
-8
@@ -6,33 +6,40 @@ use sqlx::query::Query;
|
||||
use sqlx::MySql;
|
||||
use tokens::tokens::users::UserToken;
|
||||
|
||||
pub struct UpsertAnalyticsActiveUser {
|
||||
pub struct UpsertAnalyticsAppActiveUser<'a> {
|
||||
// TODO: Swap PaymentsNamespace (artcraft,fakeyou) for an AnalyticsNamespace enum.
|
||||
pub namespace: PaymentsNamespace,
|
||||
pub user_token: UserToken,
|
||||
pub ip_address: String,
|
||||
pub user_token: &'a UserToken,
|
||||
pub ip_address: &'a str,
|
||||
pub app_version: &'a str,
|
||||
}
|
||||
|
||||
impl UpsertAnalyticsActiveUser {
|
||||
impl <'a> UpsertAnalyticsAppActiveUser<'a> {
|
||||
fn query(&self) -> Query<MySql, MySqlArguments> {
|
||||
sqlx::query!(
|
||||
r#"
|
||||
INSERT INTO analytics_active_users
|
||||
INSERT INTO analytics_app_active_users
|
||||
SET
|
||||
app_namespace = ?,
|
||||
user_token = ?,
|
||||
app_version = ?,
|
||||
ip_address = ?,
|
||||
measurement_count = measurement_count + 1,
|
||||
first_active_at = NOW(),
|
||||
last_active_at = NOW()
|
||||
ON DUPLICATE KEY UPDATE
|
||||
app_version = ?,
|
||||
ip_address = ?,
|
||||
measurement_count = measurement_count + 1,
|
||||
last_active_at = NOW()
|
||||
"#,
|
||||
&self.namespace.to_str(),
|
||||
&self.user_token.as_str(),
|
||||
&self.ip_address,
|
||||
// Insert case
|
||||
self.namespace.to_str(),
|
||||
self.user_token.as_str(),
|
||||
self.app_version,
|
||||
self.ip_address,
|
||||
// Update case
|
||||
self.app_version,
|
||||
self.ip_address,
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user