Changeset View
Changeset View
Standalone View
Standalone View
src/service/plugins/sqlite/ResourceScoreCache.cpp
Show All 32 Lines | |||||
33 | #include "StatsPlugin.h" | 33 | #include "StatsPlugin.h" | ||
34 | #include "Database.h" | 34 | #include "Database.h" | ||
35 | #include "Utils.h" | 35 | #include "Utils.h" | ||
36 | 36 | | |||
37 | 37 | | |||
38 | class ResourceScoreCache::Queries { | 38 | class ResourceScoreCache::Queries { | ||
39 | private: | 39 | private: | ||
40 | Queries() | 40 | Queries() | ||
41 | : createResourceScoreCacheQuery(resourcesDatabase().createQuery()) | 41 | : createResourceScoreCacheQuery(resourcesDatabase()->createQuery()) | ||
42 | , getResourceScoreCacheQuery(resourcesDatabase().createQuery()) | 42 | , getResourceScoreCacheQuery(resourcesDatabase()->createQuery()) | ||
43 | , updateResourceScoreCacheQuery(resourcesDatabase().createQuery()) | 43 | , updateResourceScoreCacheQuery(resourcesDatabase()->createQuery()) | ||
44 | , getScoreAdditionQuery(resourcesDatabase().createQuery()) | 44 | , getScoreAdditionQuery(resourcesDatabase()->createQuery()) | ||
45 | { | 45 | { | ||
46 | 46 | | |||
47 | Utils::prepare(resourcesDatabase(), | 47 | Utils::prepare(*resourcesDatabase(), | ||
48 | createResourceScoreCacheQuery, QStringLiteral( | 48 | createResourceScoreCacheQuery, QStringLiteral( | ||
49 | "INSERT INTO ResourceScoreCache " | 49 | "INSERT INTO ResourceScoreCache " | ||
50 | "VALUES (:usedActivity, :initiatingAgent, :targettedResource, " | 50 | "VALUES (:usedActivity, :initiatingAgent, :targettedResource, " | ||
51 | "0, 0, " // type, score | 51 | "0, 0, " // type, score | ||
52 | ":firstUpdate, " // lastUpdate | 52 | ":firstUpdate, " // lastUpdate | ||
53 | ":firstUpdate)" | 53 | ":firstUpdate)" | ||
54 | )); | 54 | )); | ||
55 | 55 | | |||
56 | Utils::prepare(resourcesDatabase(), | 56 | Utils::prepare(*resourcesDatabase(), | ||
57 | getResourceScoreCacheQuery, QStringLiteral( | 57 | getResourceScoreCacheQuery, QStringLiteral( | ||
58 | "SELECT cachedScore, lastUpdate, firstUpdate FROM ResourceScoreCache " | 58 | "SELECT cachedScore, lastUpdate, firstUpdate FROM ResourceScoreCache " | ||
59 | "WHERE " | 59 | "WHERE " | ||
60 | ":usedActivity = usedActivity AND " | 60 | ":usedActivity = usedActivity AND " | ||
61 | ":initiatingAgent = initiatingAgent AND " | 61 | ":initiatingAgent = initiatingAgent AND " | ||
62 | ":targettedResource = targettedResource " | 62 | ":targettedResource = targettedResource " | ||
63 | )); | 63 | )); | ||
64 | 64 | | |||
65 | Utils::prepare(resourcesDatabase(), | 65 | Utils::prepare(*resourcesDatabase(), | ||
66 | updateResourceScoreCacheQuery, QStringLiteral( | 66 | updateResourceScoreCacheQuery, QStringLiteral( | ||
67 | "UPDATE ResourceScoreCache SET " | 67 | "UPDATE ResourceScoreCache SET " | ||
68 | "cachedScore = :cachedScore, " | 68 | "cachedScore = :cachedScore, " | ||
69 | "lastUpdate = :lastUpdate " | 69 | "lastUpdate = :lastUpdate " | ||
70 | "WHERE " | 70 | "WHERE " | ||
71 | ":usedActivity = usedActivity AND " | 71 | ":usedActivity = usedActivity AND " | ||
72 | ":initiatingAgent = initiatingAgent AND " | 72 | ":initiatingAgent = initiatingAgent AND " | ||
73 | ":targettedResource = targettedResource " | 73 | ":targettedResource = targettedResource " | ||
74 | )); | 74 | )); | ||
75 | 75 | | |||
76 | Utils::prepare(resourcesDatabase(), | 76 | Utils::prepare(*resourcesDatabase(), | ||
77 | getScoreAdditionQuery, QStringLiteral( | 77 | getScoreAdditionQuery, QStringLiteral( | ||
78 | "SELECT start, end " | 78 | "SELECT start, end " | ||
79 | "FROM ResourceEvent " | 79 | "FROM ResourceEvent " | ||
80 | "WHERE " | 80 | "WHERE " | ||
81 | ":usedActivity = usedActivity AND " | 81 | ":usedActivity = usedActivity AND " | ||
82 | ":initiatingAgent = initiatingAgent AND " | 82 | ":initiatingAgent = initiatingAgent AND " | ||
83 | ":targettedResource = targettedResource AND " | 83 | ":targettedResource = targettedResource AND " | ||
84 | "start > :start " | 84 | "start > :start " | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
148 | 148 | | |||
149 | void ResourceScoreCache::update() | 149 | void ResourceScoreCache::update() | ||
150 | { | 150 | { | ||
151 | QDateTime lastUpdate; | 151 | QDateTime lastUpdate; | ||
152 | QDateTime firstUpdate; | 152 | QDateTime firstUpdate; | ||
153 | QDateTime currentTime = QDateTime::currentDateTime(); | 153 | QDateTime currentTime = QDateTime::currentDateTime(); | ||
154 | qreal score = 0; | 154 | qreal score = 0; | ||
155 | 155 | | |||
156 | DATABASE_TRANSACTION(resourcesDatabase()); | 156 | DATABASE_TRANSACTION(*resourcesDatabase()); | ||
157 | 157 | | |||
158 | qDebug() << "Creating the cache for: " << d->resource; | 158 | qDebug() << "Creating the cache for: " << d->resource; | ||
159 | 159 | | |||
160 | // This can fail if we have the cache already made | 160 | // This can fail if we have the cache already made | ||
161 | auto isCacheNew = Utils::exec( | 161 | auto isCacheNew = Utils::exec( | ||
162 | Utils::IgnoreError, Queries::self().createResourceScoreCacheQuery, | 162 | Utils::IgnoreError, Queries::self().createResourceScoreCacheQuery, | ||
163 | ":usedActivity", d->activity, | 163 | ":usedActivity", d->activity, | ||
164 | ":initiatingAgent", d->application, | 164 | ":initiatingAgent", d->application, | ||
▲ Show 20 Lines • Show All 99 Lines • Show Last 20 Lines |