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

feat: PPT-1475 mark Trigger fields to ignore from ES index #273

Merged
merged 5 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
46 changes: 44 additions & 2 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,50 @@
Lint/UselessAssign:
Description: Disallows useless variable assignments
Enabled: false
Severity: Warning

Naming/BlockParameterName:
Description: Disallows non-descriptive block parameter names
Enabled: false
Severity: Convention

Lint/NotNil:
Description: Identifies usage of `not_nil!` calls
Enabled: false
Style/PredicateName:
Severity: Warning

Lint/SpecFilename:
Description: Enforces spec filenames to have `_spec` suffix
Enabled: false
Severity: Warning

Style/ParenthesesAroundCondition:
Description: Disallows redundant parentheses around control expressions
Enabled: false
Severity: Convention

Naming/AccessorMethodName:
Description: Makes sure that accessor methods are named properly
Enabled: false
Severity: Convention

Naming/PredicateName:
Description: Disallows tautological predicate names
Enabled: false
Severity: Convention

Documentation/DocumentationAdmonition:
Description: Reports documentation admonitions
Enabled: false
Severity: Warning

Naming/QueryBoolMethods:
Description: Reports boolean properties without the `?` suffix
Enabled: false
Severity: Convention

Style/PredicateName:
Enabled: false

Style/QueryBoolMethods:
Enabled: false
Enabled: false
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ services:
- ${PWD}/shard.override.yml:/app/shard.override.yml
- ${PWD}/shard.yml:/app/shard.yml.input
- ${PWD}/coverage:/app/coverage
- ${PWD}/.ameba.yml:/app/.ameba.yml
depends_on:
- migrator
- postgres
Expand Down
30 changes: 30 additions & 0 deletions src/placeos-models/base/model.cr
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,37 @@ end

# :nodoc:
module Time::EpochConverter
def self.from_rs(rs : DB::ResultSet)
rs.read(Time)
end
end

module Time::EpochConverterOptional
def self.from_rs(rs : DB::ResultSet)
rs.read(Time?)
end

def self.from_json(value : JSON::PullParser) : Time?
str = value.read_raw
return nil unless str
if (val = str.to_i?)
Time.unix(val)
else
begin
Time.from_json(str)
rescue Time::Format::Error
fmt = "%FT%T"
fmt += ".%6N" if str.index('.')
Time.parse_utc(str.strip('"'), fmt)
end
end
end

def self.to_json(value : Time?, json : JSON::Builder) : Nil
if val = value
json.number(val.to_unix)
else
json.null
end
end
end
2 changes: 1 addition & 1 deletion src/placeos-models/edge.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module PlaceOS::Model
attribute api_key_id : String, mass_assignment: false

attribute user_id : String, mass_assignment: false
attribute last_seen : Time?, mass_assignment: false
attribute last_seen : Time?, converter: Time::EpochConverterOptional, mass_assignment: false
attribute online : Bool = false, mass_assignment: false

@[JSON::Field(ignore: true)]
Expand Down
2 changes: 1 addition & 1 deletion src/placeos-models/module.cr
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module PlaceOS::Model

# Runtime Error Indicators
attribute has_runtime_error : Bool = false, mass_assignment: false
attribute error_timestamp : Time? = nil, converter: Time::EpochConverter, type: "integer", format: "Int64", mass_assignment: false
attribute error_timestamp : Time? = nil, converter: Time::EpochConverterOptional, type: "integer", format: "Int64", mass_assignment: false

# Associations
###############################################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/placeos-models/shortener.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module PlaceOS::Model
attribute redirect_count : Int64 = 0
attribute enabled : Bool = true

attribute valid_from : Time? = nil, converter: Time::EpochConverter
attribute valid_until : Time? = nil, converter: Time::EpochConverter
attribute valid_from : Time? = nil, converter: Time::EpochConverterOptional
attribute valid_until : Time? = nil, converter: Time::EpochConverterOptional

belongs_to Authority

Expand Down
2 changes: 1 addition & 1 deletion src/placeos-models/tenant.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module PlaceOS::Model
attribute delegated : Bool = false
attribute service_account : String?

attribute secret_expiry : Time?, converter: Time::EpochConverter
attribute secret_expiry : Time?, converter: Time::EpochConverterOptional
attribute early_checkin : Int64 = 3600

has_many(
Expand Down
4 changes: 2 additions & 2 deletions src/placeos-models/trigger.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module PlaceOS::Model
attribute description : String = ""

# Full path allows resolution in macros
attribute actions : PlaceOS::Model::Trigger::Actions = ->{ Actions.new }, es_type: "object"
attribute conditions : PlaceOS::Model::Trigger::Conditions = ->{ Conditions.new }, es_type: "object"
attribute actions : PlaceOS::Model::Trigger::Actions = ->{ Actions.new }, es_ignore: true
attribute conditions : PlaceOS::Model::Trigger::Conditions = ->{ Conditions.new }, es_ignore: true

# In milliseconds
attribute debounce_period : Int32 = 0
Expand Down
2 changes: 1 addition & 1 deletion src/placeos-models/trigger/conditions.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module PlaceOS::Model
end

attribute type : Type
attribute time : Time?, converter: Time::EpochConverter, type: "integer", format: "Int64"
attribute time : Time?, converter: Time::EpochConverterOptional, type: "integer", format: "Int64"
attribute cron : String?
attribute timezone : String?

Expand Down
2 changes: 1 addition & 1 deletion src/placeos-models/user.cr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module PlaceOS::Model
attribute support : Bool = false, mass_assignment: false

attribute login_count : Int64 = 0
attribute last_login : Time? = nil, converter: Time::EpochConverter
attribute last_login : Time? = nil, converter: Time::EpochConverterOptional, type: "integer", format: "Int64"

attribute work_preferences : Array(WorktimePreference) = [] of WorktimePreference, converter: PlaceOS::Model::DBArrConverter(PlaceOS::Model::User::WorktimePreference)
attribute work_overrides : Hash(String, WorktimePreference) = {} of String => WorktimePreference, converter: PlaceOS::Model::DBHashConverter(String, PlaceOS::Model::User::WorktimePreference)
Expand Down
Loading