mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Use an upsert statement for handling pubsub.
This commit is contained in:
parent
6a2c688f50
commit
1dbda14335
1 changed files with 7 additions and 10 deletions
|
@ -57,17 +57,14 @@ public class PubSubHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void updatePubSub(String channelId) {
|
public static void updatePubSub(String channelId) {
|
||||||
var pubsub = DatabaseHelper.getPubSubFromId(channelId);
|
|
||||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||||
s.beginTransaction();
|
var tr = s.beginTransaction();
|
||||||
if (pubsub == null) {
|
s.createNativeMutationQuery("INSERT INTO pubsub (id, subbed_at) VALUES (?, ?) " +
|
||||||
pubsub = new PubSub(channelId, System.currentTimeMillis());
|
"ON CONFLICT (id) DO UPDATE SET subbed_at = excluded.subbed_at")
|
||||||
s.insert(pubsub);
|
.setParameter(1, channelId)
|
||||||
} else {
|
.setParameter(2, System.currentTimeMillis())
|
||||||
pubsub.setSubbedAt(System.currentTimeMillis());
|
.executeUpdate();
|
||||||
s.update(pubsub);
|
tr.commit();
|
||||||
}
|
|
||||||
s.getTransaction().commit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue