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) {
|
||||
var pubsub = DatabaseHelper.getPubSubFromId(channelId);
|
||||
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
|
||||
s.beginTransaction();
|
||||
if (pubsub == null) {
|
||||
pubsub = new PubSub(channelId, System.currentTimeMillis());
|
||||
s.insert(pubsub);
|
||||
} else {
|
||||
pubsub.setSubbedAt(System.currentTimeMillis());
|
||||
s.update(pubsub);
|
||||
}
|
||||
s.getTransaction().commit();
|
||||
var tr = s.beginTransaction();
|
||||
s.createNativeMutationQuery("INSERT INTO pubsub (id, subbed_at) VALUES (?, ?) " +
|
||||
"ON CONFLICT (id) DO UPDATE SET subbed_at = excluded.subbed_at")
|
||||
.setParameter(1, channelId)
|
||||
.setParameter(2, System.currentTimeMillis())
|
||||
.executeUpdate();
|
||||
tr.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue