Skip to content
Next
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Minds Backend - Engine
Project
Project
Details
Activity
Releases
Dependency List
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
186
Issues
186
List
Boards
Labels
Service Desk
Milestones
Merge Requests
33
Merge Requests
33
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
List
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Minds
Minds Backend - Engine
Commits
866a01b0
Commit
866a01b0
authored
14 minutes ago
by
Emiliano Balbuena
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(refactor): Single campaigns should be fetch from Cassandra
parent
f3b1fddd
goal/boost-campaigns-e24
1 merge request
!235
WIP: Boost Campaigns (&24)
Pipeline
#73581229
passed with stages
in 9 minutes
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
20 deletions
+105
-20
Dispatcher.php
Core/Boost/Campaigns/Dispatcher.php
+1
-1
Manager.php
Core/Boost/Campaigns/Manager.php
+16
-3
Repository.php
Core/Boost/Campaigns/Repository.php
+84
-5
cassandra-provision.cql
Core/Provisioner/Provisioners/cassandra-provision.cql
+4
-11
No files found.
Core/Boost/Campaigns/Dispatcher.php
View file @
866a01b0
...
...
@@ -10,7 +10,7 @@ use Exception;
class
Dispatcher
{
const
IMPRESSIONS_SYNC_THRESHOLD
=
1
;
const
IMPRESSIONS_SYNC_THRESHOLD
=
5
;
/** @var Manager */
protected
$manager
;
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/Manager.php
View file @
866a01b0
...
...
@@ -102,7 +102,15 @@ class Manager
*/
public
function
getList
(
array
$opts
=
[])
{
return
$this
->
elasticRepository
->
getList
(
$opts
)
->
map
(
function
(
Campaign
$campaign
)
{
$opts
=
array_merge
([
'useElastic'
=>
true
],
$opts
);
$response
=
$opts
[
'useElastic'
]
?
$this
->
elasticRepository
->
getList
(
$opts
)
:
$this
->
repository
->
getList
(
$opts
);
return
$response
->
map
(
function
(
Campaign
$campaign
)
{
try
{
$campaign
->
setPayments
(
...
...
@@ -141,8 +149,12 @@ class Manager
* @return Campaign|null
* @throws Exception
*/
public
function
get
(
$urn
)
public
function
get
(
$urn
,
array
$opts
=
[]
)
{
$opts
=
array_merge
([
'useElastic'
=>
false
],
$opts
);
$urn
=
new
Urn
(
$urn
);
$guid
=
$urn
->
getNss
();
...
...
@@ -151,7 +163,8 @@ class Manager
}
$campaigns
=
$this
->
getList
([
'guid'
=>
$guid
'guid'
=>
$guid
,
'useElastic'
=>
$opts
[
'useElastic'
],
])
->
toArray
();
if
(
!
$campaigns
)
{
...
...
This diff is collapsed.
Click to expand it.
Core/Boost/Campaigns/Repository.php
View file @
866a01b0
...
...
@@ -6,12 +6,15 @@
namespace
Minds\Core\Boost\Campaigns
;
use
Cassandra\Varint
;
use
Cassandra\Bigint
;
use
Cassandra\Rows
;
use
Exception
;
use
Minds\Common\Repository\Response
;
use
Minds\Core\Data\Cassandra\Client
as
CassandraClient
;
use
Minds\Core\Data\Cassandra\Prepared\Custom
;
use
Minds\Core\Di\Di
;
use
Minds\Helpers\Number
;
use
Minds\Helpers\Text
;
use
NotImplementedException
;
class
Repository
...
...
@@ -32,11 +35,87 @@ class Repository
/**
* @param array $opts
* @throws NotImplementedException
* @return Response
* @throws Exception
*/
public
function
getList
(
array
$opts
=
[])
{
throw
new
NotImplementedException
();
$opts
=
array_merge
([
'limit'
=>
12
,
'offset'
=>
null
,
'guid'
=>
null
,
],
$opts
);
if
(
!
$opts
[
'guid'
])
{
throw
new
\Exception
(
'Cassandra getList only supports GUID constraint'
);
}
$cql
=
"SELECT * FROM boost_campaigns WHERE guid = ?"
;
$values
=
[
new
Bigint
(
$opts
[
'guid'
])
];
$cqlOpts
=
[];
if
(
$opts
[
'limit'
])
{
$cqlOpts
[
'page_size'
]
=
(
int
)
$opts
[
'limit'
];
}
if
(
$opts
[
'offset'
])
{
$cqlOpts
[
'paging_state_token'
]
=
base64_decode
(
$opts
[
'offset'
]);
}
$prepared
=
new
Custom
();
$prepared
->
query
(
$cql
,
$values
);
$prepared
->
setOpts
(
$cqlOpts
);
$response
=
new
Response
();
try
{
/** @var Rows $rows */
$rows
=
$this
->
db
->
request
(
$prepared
);
if
(
$rows
)
{
foreach
(
$rows
as
$row
)
{
$campaign
=
new
Campaign
();
$campaign
->
setUrn
(
"urn:campaign:
{
$row
[
'guid'
]
->
toInt
()
}
"
)
->
setOwnerGuid
(
$row
[
'owner_guid'
]
->
toInt
())
->
setType
(
$row
[
'type'
]);
$data
=
json_decode
(
$row
[
'json_data'
]
?:
'{}'
,
true
);
$campaign
->
setName
(
$data
[
'name'
])
->
setEntityUrns
(
Text
::
buildArray
(
$data
[
'entity_urns'
]))
->
setHashtags
(
Text
::
buildArray
(
$data
[
'hashtags'
]))
->
setNsfw
(
Number
::
buildIntArray
(
$data
[
'nsfw'
]))
->
setStart
((
int
)
$data
[
'start'
])
->
setEnd
((
int
)
$data
[
'end'
])
->
setBudget
((
string
)
$data
[
'budget'
])
->
setBudgetType
(
$data
[
'budget_type'
])
->
setChecksum
(
$data
[
'checksum'
])
->
setImpressions
((
int
)
$data
[
'impressions'
])
->
setImpressionsMet
(
$data
[
'impressions_met'
])
->
setRating
(
$data
[
'rating'
])
->
setQuality
(
$data
[
'quality'
])
->
setCreatedTimestamp
(((
int
)
$data
[
'timestamp_timestamp'
])
?:
null
)
->
setReviewedTimestamp
(((
int
)
$data
[
'reviewed_timestamp'
])
?:
null
)
->
setRejectedTimestamp
(((
int
)
$data
[
'rejected_timestamp'
])
?:
null
)
->
setRevokedTimestamp
(((
int
)
$data
[
'revoked_timestamp'
])
?:
null
)
->
setCompletedTimestamp
(((
int
)
$data
[
'completed_timestamp'
])
?:
null
);
$response
[]
=
$campaign
;
}
$response
->
setPagingToken
(
base64_encode
(
$rows
->
pagingStateToken
()));
$response
->
setLastPage
(
$rows
->
isLastPage
());
}
}
catch
(
Exception
$e
)
{
$response
->
setException
(
$e
);
}
return
$response
;
}
/**
...
...
@@ -49,8 +128,8 @@ class Repository
$cql
=
"INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)"
;
$values
=
[
$campaign
->
getType
(),
new
Var
int
(
$campaign
->
getGuid
()),
new
Var
int
(
$campaign
->
getOwnerGuid
()),
new
Big
int
(
$campaign
->
getGuid
()),
new
Big
int
(
$campaign
->
getOwnerGuid
()),
json_encode
([
'urn'
=>
$campaign
->
getUrn
(),
'owner_guid'
=>
(
string
)
$campaign
->
getOwnerGuid
(),
...
...
This diff is collapsed.
Click to expand it.
Core/Provisioner/Provisioners/cassandra-provision.cql
View file @
866a01b0
...
...
@@ -1447,20 +1447,13 @@ CREATE TABLE minds.email_campaign_logs (
) WITH CLUSTERING ORDER BY (time_sent desc);
CREATE TABLE minds.boost_campaigns (
guid bigint,
owner_guid bigint,
type text,
guid varint,
owner_guid varint,
json_data text,
delivery_status text,
PRIMARY KEY (type, guid)
) WITH CLUSTERING ORDER BY (guid ASC);
CREATE MATERIALIZED VIEW minds.boost_campaigns_by_owner AS
SELECT *
FROM minds.boost_campaigns
WHERE type IS NOT null AND owner_guid IS NOT null AND guid IS NOT null
PRIMARY KEY (type, owner_guid, guid)
WITH CLUSTERING ORDER BY (owner_guid ASC, guid DESC);
PRIMARY KEY (guid)
);
CREATE TABLE minds.boost_campaigns_payments (
owner_guid bigint,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment